I wish to have the form to be able to automatically select the radio button based on the logic of HTML/php variable. example show below:
javascript:
[CODE=javascript]function autoForm(value)
{
var myForm = document.forms["search"];
if (value == '1')
myForm.elements["category"][0].checked = true;
if (value == '0')
myForm.elements["category"][1].checked = true;
}[/CODE]
[CODE=html]<body onload = "autoForm('1')" >[/CODE]
html:
[HTML]<form name = "search">
<input type = "radio" name = "category"/>category 1
<input type = "radio" name = "category"/>category 2
<?php
$value = '1'; /* with either 1 or 0 */
?>
</form>[/HTML]
Question:
if I pass value as constant, it will work as shown in next line code,
<body onload = "autoForm('1')" > or <body onload = "autoForm('0')" >
if I pass value as variable from php, it doesn't work at all,
<body onload = "autoForm("$val ue")">
How I can pass value of variable from html/php into Java Script ?
Thanks for ur insight..
javascript:
[CODE=javascript]function autoForm(value)
{
var myForm = document.forms["search"];
if (value == '1')
myForm.elements["category"][0].checked = true;
if (value == '0')
myForm.elements["category"][1].checked = true;
}[/CODE]
[CODE=html]<body onload = "autoForm('1')" >[/CODE]
html:
[HTML]<form name = "search">
<input type = "radio" name = "category"/>category 1
<input type = "radio" name = "category"/>category 2
<?php
$value = '1'; /* with either 1 or 0 */
?>
</form>[/HTML]
Question:
if I pass value as constant, it will work as shown in next line code,
<body onload = "autoForm('1')" > or <body onload = "autoForm('0')" >
if I pass value as variable from php, it doesn't work at all,
<body onload = "autoForm("$val ue")">
How I can pass value of variable from html/php into Java Script ?
Thanks for ur insight..
Comment