Im new to php, I dont have good idea how to make things between php and javascript please correct me If im wrong
<!doctype html>
<html>
<head>
<Script type="text/javascript">
function show(m)
{
var k = document.getElementById(m);
k.src="four.jpg";
}
</head>
<body>
<? --some php code--
$i = 2;
$row[$i] = "somefilename";
printf('<img src="%s" id="%d" onclick="show($i)"/>', $row[$i],$i);
?>
This is my sample.php file.I wanted to raise a onclick event for the image tag through javascript,The img tag is created using php script and I want it to be like these
onclick="show($i)" should be made like below
onclick="show('2')" <!-- and here 2 is the value of php variable
I had tried these way
onclick="show('$i')" but it passes $i as the parameter to javascript show() function
but not the value 2
Please help me with these. actually is it possible ? As i know javascript is a browser scripting and php is server side scripting and can we pass variables from php to javascript these way ?