I am trying to load an image by setting a php variable $image = "0005.jpg"
on click of the button this function is called login('$image')
I have a alert() to tell me if something was passed to it. my way of debugging.
I am still very new to php, and javascript, but having fun learning.
It works perfectly, I did a lot of searching about passing php values to javascript function, and nothing showed what you have shown. Can you explain why it works? Thanks for the help!
So it works, but when I went to apply directly to my game, the above was a simple example of loading an image. I want to pass $id to loadimage() when an opponent is selected from a dropdown list:
}
$id= "0005.jpg";
?>
<strong>Select Opponent:</strong>
<select id='opponent' name='opponent' onChange='select_opponent();loadimage('$id')'>
<OPTION VALUE=0>Choose your opponent
<?=$options?>
</SELECT>
---------------------------------------------------
while ($row=mysql_fetch_array($result)) {
I think you are geting confused to as when you are in PHP and when you are not, Both lines that call loadImage() are NOT in PHP code, so you are passing to loadImage the actual string $id. You would need to do something like loadImage('<?php echo $id; ?>');
As to the earlier question, the reason it worked is you are concatenating the string <img src= ' with the contents of the variable t and then with the string ' alt=''/>
(in php you would do "string1" . $variable . "string2" where in JS, you do "string1" + variable + "string2"