Forum Moderators: coopster
$output = "<table>";
$output.= "<tbody>";
foreach($results as $result)
{
$output.= "<tr>";
$output.= "<td>".date("m/d/y",$result['datestamp'])."</td>";
$output.= "<td><a href='" . "' target='_self'>{$result['title']}</a></td>";
$output.="</tr>";
}
$output.= "</tbody>";
$output.= "</table>";
Simple enough. However, in each of those a href links, I want to have an onclick event sent to a javascript function, do_ajax. Specifically, I want to be able to send the function an ID number, so that the javascript can update the page with the click (without having to refresh it). So, say, the 4th item will have an ID = 4, and I want the javascript to be able to intercept that number and do its thing. Getting to syntax just write seems to be killing me though -- I'm fairly new to web programming (Java/C# programmer).
Thanks!
$output.= '<td><a href="" target="_self" ';
$output.= 'onclick="do_ajax('.$result['id'].');">';
$output.= $result['title'] .'</a></td>';
Which gives you something like
<a href="" target="_self" onclick="do_ajax(4);">title</a>
You could also assign a class to each anchor element, and use a DOM function in a SCRIPT element to parse through and find the anchors that match this specific class, then assign the click event to those anchor tags.
Thanks