javascript - Is it possible to get the value of a <td> element using onclick? -
i have table has list of email template names being echoed using php. below part of php code. i'm trying grab table value , pass js file future ajax command pass different file (that won't have issues with). first attempt alert out value stated value undefined. second attempt showed type of element inside (at time span). 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 depts 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 emails bus_id = '{$_session['bus_id']}' order 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); }
javascript:
var y = document.getelementbyid("test").innertext;
jquery:
$("#test").text();
to html:
var html = document.getelementbyid("test" ).innerhtml;
jquery:
$("#test").html();
Comments
Post a Comment