i am trying to create a javascript function which is called by the onClick property and has a parameter that I can set with PHP. I can get everything to work, mostly. But i can’t get it to to submit a form with a name that is set by the parameter of the function.
<html>
<body>
<?
$item=”1235″;
?>
<form name=’1235′ action=”order.php” method=”get”>
<input type=”text” name=”p1″ value=”<? echo $item; ?>” onClick=”submitSplit(<? echo $item; ?>)”>
<input type=”button” value=”go” >
</form>
<script>
function submitSplit(test_var)
{
document.forms[test_var].submit();
}
</script>
</body>
</html>
i also tried using a javascript variable whose value had been set in PHP, like below. The writeln(item) line works, but the
submitSplit(item) function doesn’t.
<html>
<body>
$item=”1234″;
echo “<script language=”JavaScript”>n”;
echo “<!– hide from older browsersn”;
echo ” var item = “$item”;n”;
echo “// –>n”;
echo “</script>n”;
?>
<form name=’1235′ action=”order.php” method=”get”>
<input type=”text” name=”p1″ value=”<? echo $item; ?>” onClick=”submitSplit(item)”>
<input type=”button” value=”go” >
</form>
<script>
document.writeln(item);
function submitSplit(test_var){
document.forms[test_var].submit();
}
</script>
</body>
</html>