Determine if Radio Button is selected values

N

Nongo

How come I can access a button's value, but not a radio
button's value? As in the following:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Test Radio Buttons</title>
</head>

<script language=JavaScript>
function ShowValues() {
alert(form1.B1.value); // Prompts correctly with "Button"
alert(form1.R1.value); // Prompts with "undefined"
}
</script>

<body onclick="ShowValues()">
<form name="form1" method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-
File="fpweb:///_private/form_results.txt"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><input type="radio" value="V1" checked name="R1"></p>
<p><input type="radio" name="R1" value="V2"></p>
<p><input type="submit" value="Button" name="B1">
</form>
</body>
</html>

Put in another way - how does one determine which of the
radion buttons is selected?

Thanks in advance.
 
J

jon spivey

Hi,
not as simple as that, javascript's handling of radios isnt as smart as say
ASP - you have to address each radio individually and see if it's checked
or not
<script>
function checkIt(f){
for(i=0;i<f.test.length;i++){
if(f.test.checked)alert(f.test.value)
}}
</script>
<form>
<input type="radio" name="test" value="1">
<input type="radio" name="test" value="2">
<input type="button" onclick="checkIt(this.form)">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top