<a href="#" onclick='contacts($code)'>Contact Details</a>

This runs a jquery code with the value $code. in Firebug I can see it gets the correct rowset value,
the jquery is below:

function contacts(code){
  jQuery.ajaxSetup({async:true});
  jQuery.post("php/contact.php", {code: code}, function(data) {
$('#results').hide();
$('#results').fadeIn(2000);
$('#results').show() .html(data);
});
}

it is supposed to post this value to the contact.php page, which has worked perfectly in other applications ive written using this method.

I keep getting ReferenceError: UA11 is not defined (UA11 being the rowset value) in firebug.

Cant seem to work out whats wrong?

Check out a couple of things to help diagnose what is wrong. You may have already tried some of these, but just in case:

  1. Make sure that the correct value is being passed into the function - either set a breakpoint on line 2 or print the value of code. Also, if the $code variable is a PHP variable, it should be wrapped in <? ?>.

  2. Check your contact.php file thoroughly, to make it easier, pass in an expected value through a url manually (e.g. contact.php?code=14), and check it all works with $_GET['code'], you can change it back to using POST after you are sure the contact file works as expected.

  3. On that point, make sure you are retrieving code using $_POST['code'] and not $_GET['code'] when using the function.

  4. Try changing jQuery to $.

  5. Try using the ajax method instead:

    var request = $.ajax({
    url: "php/contact.php",
    type: "POST",
    data: { code : code },
    dataType: "html"
    });

    request.done(function(data) {
    $('#results').hide();
    $('#results').fadeIn(2000);
    $('#results').show() .html(data);
    });

Hope this helps!

Thanks, I have checked all the above to no avail, the part of my code that is supposed to post the value is here:

$alias = $row['Site_Alias'];
$alias = str_replace('_', ' ', $alias);
$hostname = $row['Hostname'];
$code = trim($hostname, '()');
$code = substr($code, 0, 4);
echo <<<EOF
<table width="100%" border=0">
<tr><td  class="grey">$status $psba - Customer - $newresult - $hostname - $alias <span class='contact'><a href="#" onclick='contacts($code)'>Contact Details</a></span></td><td class="red" rowspan="2">$street<br />$city<br /> $county, $zip</td></tr>
<tr><td class="green"> <span class='circuit'>$circuit </span><span class='bte'>$exchange</span></td></tr>
</table>
EOF;
}

it shows the correct variable, but nothing is being posted...i set a static value in contracts() and thats not being posted anywhere either.. Im lost!

keeps on saying its undefined.. doesnt tell what is undefined though, im sure the issue lies with the onclick and jquery... but the exact same code worked on my previous app.. most annoying!

I think I know what's wrong, try wrapping the $code variable in double quotes:

onclick='contacts("$code")'

Let me know if that fixes it!

BIG SIGH

Thankyou Anthony21 for looking at this, 2nd pair of eyes is always good!
this has solved the issue, many many thanks.

No worries, glad to be of help! :)

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.