Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2012, 09:45 PM   PM User | #1
dk4210
New Coder

 
Join Date: Nov 2002
Posts: 99
Thanks: 13
Thanked 0 Times in 0 Posts
dk4210 is an unknown quantity at this point
php var to ajax script via onclick

Hello Guys,

Is there a way that I can pass a PHP var to the ajax script via an onclick event? I am trying to pass the var - $imgid

Here is my link

PHP Code:
  echo '<a href="artists/'.$artist.'/'.$imgid.'.jpg?imgid='.$imgid.'" onclick="loadXMLDoc()" class="thumbnail" ><img src="artists/'.$artist.'/previews/'.$imgid.'.jpg" border="0" /></a>'
Here is the Ajax call

PHP Code:
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","artist_title.php?imgid=<?php echo $imgid?>",true);
xmlhttp.send();
}
</script>

Please advise..
Thanks, Dan
dk4210 is offline   Reply With Quote
Old 03-09-2012, 09:46 PM   PM User | #2
dk4210
New Coder

 
Join Date: Nov 2002
Posts: 99
Thanks: 13
Thanked 0 Times in 0 Posts
dk4210 is an unknown quantity at this point
Every time I add something to the onclick it breaks the ajax call
dk4210 is offline   Reply With Quote
Old 03-10-2012, 01:43 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,376
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Move the onclick to the img tag. And do you want to load another page, the
Code:
<a href="
in the anchor tag, if your calling an ajax function?
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:25 AM.


Advertisement
Log in to turn off these ads.