Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  67] [ 4]  / answers: 1 / hits: 34936  / 11 Years ago, thu, august 8, 2013, 12:00:00

I currently have a table that has a list of email template names being echoed using php. Below is part of the php code. I'm trying to grab the table value and pass it to my JS file where a future AJAX command will pass it to a different file (that I won't have any issues with). My first attempt to alert out the value stated that the value was undefined. My second attempt showed the type of element it was inside (at the time it was a span). Now it's not showing anything. Suggestions?



PHP code:



<table class=departments>
<tr>
<th scope=col style=width: 175px;>Email Name</th>
';
$get_depts = mysql_query(SELECT dept_name FROM depts where bus_id = '{$_SESSION['bus_id']}');
while(($department = mysql_fetch_assoc($get_depts)))
{
echo '
<th scope=col style=width: 175px;>'.$department['dept_name'].'</th>
';
}
echo '
</tr>
';
$get_emails = mysql_query(SELECT id, email_name from emails where bus_id = '{$_SESSION['bus_id']}' ORDER BY email_name ASC);
while(($email = mysql_fetch_assoc($get_emails)))
{
echo '
<tr>
<td id=test onclick=moveValue()>'.$email['email_name'].'</td>
';


Current JS code:



function moveValue()
{
var x = document.getElementById(test);
var y = x.innerHTML;
alert(y);
}

More From » onclick

 Answers
32

Javascript:



var y = document.getElementById(test).innerText;


jQuery:



$(#test).text();


To get the HTML:



var html = document.getElementById(test ).innerHTML;


jQuery:



$(#test).html();

[#76461] Wednesday, August 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;