Radio Buttons og Form
Har et problem med nedenstående script. Det virker fint, og gør opmærksom hvis brugeren ikke har valgt en radio button. Problemet er bare, at det eksekverer "action"-delen i form-tag'et alligevel, og derfor hopper videre til næste side.Hvordan får jeg scriptet til at blive på siden hvis der er fejl?
<script>
var radio_selection="";
var radio_selection2="";
function radioButtons(questionForm) {
if (radio_selection=="") {
alert("\nYou must check one of the radio buttons.");
questionForm.radiobutton.Focus();
return (false);
}
if (radio_selection2=="") {
alert("\nYou must check one of the radio buttons.");
questionForm.radiobutton2.Focus();
return (false);
}
return (true);
}
</script>
</head>
<body>
<FORM method='post' action='sss.htm' onSubmit='radioButtons(this)' name='questionForm'>
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='yes'">YES<br>
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='no'">NO<br>
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='maybe'">MAYBE<p>
<INPUT TYPE="radio" NAME="radiobutton2" onClick="radio_selection2='yes'">YES<br>
<INPUT TYPE="radio" NAME="radiobutton2" onClick="radio_selection2='no'">NO<br>
<INPUT TYPE="radio" NAME="radiobutton2" onClick="radio_selection2='maybe'">MAYBE<br>
<INPUT TYPE=submit VALUE="Check Form Fields" >
