Click to See Complete Forum and Search --> : radio buttons


srimca
03-04-2003, 12:32 AM
i have a opinion poll.code is as follows:
Opinion Poll:<br>
what is your opinion regarding this HelpDesk Website:<br>
<br>
<input type=radio name=r1 value=g>Good
<input type=radio name=r1 value=a>Average
<input type=radio name=r1 value=b>Bad<br><br>
<input type=hidden name=a1>
<input type=hidden name=r1ans value=b>
Cast Your Vote:
<input type=button value="Submit" ></b><br>
</form>


now i want to check first whether the button is checked or not and then capture the value of that particular checked radio button.
how to do this
thanks

gil davis
03-04-2003, 06:03 AM
<script>
function validate(fm) {
if (fm.r1[0].checked || fm.r1[1].checked || fm.r1[2].checked)
{fm.r1ans.value = (fm.r1[0].checked) ? fm.r1[0].value : (fm.r1[1].checked) ? fm.r1[1].value : fm.r1[2].value;
fm.submit();}
else
{alert("Please answer the question");}
}
</script>
...
<input type=button value="Submit" onclick="validate(this.form)">