i am fairly new to javascript, and am trying to incorporate it with PHP.
I want the variable item set in PHP to be passed to the Javascript command onClick in one of my forms. I want that command to call a Javascript function called doSubmit(item), that has item passed as the value of the parameter.
The doSubmit() function has the parameter test_var, which will take on the value "item" set by the PHP code.
Then the doSubmit function will submit a form whose name is determined by the test_var parameter.
Some of this is working, some isn't. PHP is setting the javascript variable, which has been tested by the javascript line document.writeln(item);
which works.
I have a feeling that the part that is not working is the idea of using test_var and having its value set when I call the function doSubmit() with item as the value of the parameter. Is this not doable in Javascript?
<html>
<head>
<title>Untitled Document</title>
</head>
<?
$item="test";
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from older browsers\n";
echo " var item = \"$item\";\n";
echo "// -->\n";
echo "</script>\n";
?>
</form>
<form name='test' action="order.php" method="get">
<input type="text" name="p1" value="<? echo $item; ?>" onClick="doSubmit(item)">
<input type="button" value="go" >
</form>
<script>
document.writeln(item);
function doSubmit(test_var){
document.test_var.submit();
}
</script>
</body>
</html>