I am trying to use AJAX to do a simple thing of displaying the results in the same page. Clicking on the <a href tag should display the results in the same page. This is working correctly in IE but the onclick() function is not working in firefox and safari. Below is the code, any help appreciated.


include "dbconnect.php";
<script language="JavaScript" type="text/javascript">
function display_data(id) { 
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
    var url="ajax2.php";
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
function GetXmlHttpObject() {
    var xmlhttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlhttp=new XMLHttpRequest();
    catch (e) {
        // Internet Explorer
        try {
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        catch (e) {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlhttp;

$query="SELECT AGE, experiment_name XENOID FROM Donor_Experiment limit 10";
    while(list($AGE, $XENOID)=mysql_fetch_row($result)) {
		echo '<a href="#" value="'.$XENOID.'" onclick="display_data(this.value)">'.$XENOID.'</a>';

<div id="employ_data"><div>


include "dbconnect.php";
    $query="select DONOR, SEX, DIAG, SITE from Experiment where experiment_name = '$_GET[employ_id]'";
    echo "<table border=\"1\">
            <td>Appoint Date:</td>


Recommended Answers

All 5 Replies


Can only think that Moz browsers aren't reading the value attribute in the <a> tags.

Suggest you try this:

//-- replace
//echo '<a href="#" value="'.$XENOID.'" onclick="display_data(this.value)">'.$XENOID.'</a>';
//-- with
echo "<a href=\"\" onclick=\"display_data('$XENOID');return false\">$XENOID</a>";

May be enough to make it work.


commented: Thank you very much...it worked perfectly. +0

Another thing.

In ajax2.php you need to sanitize $_GET[employ_id] , otherwise your database is open to a code injection attack.

If your ids are integers then use intval($_GET[employ_id], 10) (but note that intval() returns zero on failure). Othersise, devise a regular expression to check that $_GET[employ_id] is of the right format.


Thank you very much...it worked perfectly in ie, firefox and safari.

Hi pals,
I am also in onclick problem, my code works fine in FF,OPERA,Chrome but not in Safari.
My problem is this onclick.

<?php if(has_access($userarray,'view_serverdet','server')){
	if (('Y' == $webpanel_ajax) && ('N' == $server_details || $usergroupid == "1")) { ?>
		<span class="expand" id="exp<?php echo $server_row['id']?>" onclick="view_details('<?php echo $server_row['id'];?>','page','<?php echo $shade;?>')">+</span>
<?php }
} ?>

The corresponding function like:

function view_details(id,from,class) {
  	 alert("id is:"+id);
  	 alert("from is:"+from);
          //some other codes

In other Browsers these values alert, but in Safari not. Why Pls Give me a solution

Anes P.A

This should be a new topic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.