Forum Moderators: open
I'm no javascript wizard, but I don't understand why the following code doesn't wordk. Any Suggestions?
<SCRIPT language="JavaScript">
<!--
function OnSubmitForm()
{
if(document.pressed == 'yes')
{
document.forms[0].action ="q_5.php";
}
else(document.pressed == 'no')
{
document.forms[0].action ="q_7.php";
}
return true;
}
//-->
</SCRIPT>
<form action="q_5.php" name="form" onSubmit="return OnSubmitForm();">
yes<input type="checkbox" name="q_4" onSelect="document.pressed=this.value" value="yes">
no<input type="checkbox" name="q_4" onSelect="document.pressed=this.value" value="no">
</form>
TIA, AA
<SCRIPT type="text/javascript">
<!--
function submitForm(form)
{
if (form.q_4.checked) form.action = 'q_5.php'
else form.action = 'q_7.php';
return true;
}
//-->
</SCRIPT>
<form action="q_5.php" name="myform" onsubmit="return submitForm(this)">
<label><input type="checkbox" name="q_4" value="yes">yes</label>
</form> Kaled.
Another solution: If Javascript is disabled, create a small scriptlet to take the selected value of q_4 and direct it properly, hence the initial action in my sample is redirect.php.
Don't name a form form. form is a JS keyword referencing the current form as below. Remove the alert and this should work OK.
<script type="text/javascript">
function OnSubmitForm(form) {
form.action = (form.q_4[1].checked == true)?'q_7.php':'q_5.php';
alert(form.action);
form.submit();
}
</script>
<form action="redirect.php" name="form1" onSubmit="return false;">
yes <input type="radio" name="q_4" value="q_5.php" checked>
no <input type="radio" name="q_4" value="q_7.php">
<input type="submit" onClick="OnSubmitForm(this.form);" value="Submit">
</form>