Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button Function

Status
Not open for further replies.

jshurst

Programmer
Oct 27, 2004
1,158
US
I know that this has probably been beaten to death, but I just don't understand why this won't work. Can someone tell me what I'm doing wrong?

I would really just like to get the value of the button that is checked (or see how many elements are on the page, but I keep getting that the element isn't an object.

Code:
<html>
<head>
<script language="javascript">
function ShowMe() {
var a;
for (i=0;i<document.forms[0].radBtnPictures.length;i++) {
	a++;
	}
	alert(a)
}
</script>
</head>
<body>
<input id="ratBtnSome" type="radio" name="radBtnPictures" value="radBtnSome" /><label for="radBtnNone">Some</label>
<input id="radBtnNone" type="radio" name="radBtnPictures" value="radBtnNone" checked="checked" /><label for="radBtnNone">None</label>
<input type="button" value="Click Me" onclick="ShowMe()" />
</body>
</html>

Thanks in advance,

J
 
Try putting the radio buttons in form before you try to access a form and its elements. Then try this:
Code:
alert(document.forms[0].radBtnPictures.value);

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top