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!

Checking a RadioButtonList

Status
Not open for further replies.

iaswnidou

Programmer
Joined
Apr 19, 2005
Messages
140
Location
GR
Hello

I am trying to check if any radiobuttons of a radiobuttonlist's have been checked through this script:

Code:
var i=0;
var radiolist = document.forms[0].rdbTypeList;
for (i=0; i<=radiolist.length; i++)
  { 
  if (isNull(radiolist[i].checked))	
    {
     checked = true;
    }
  }
	  
if (checked == false)
{ alert("Property type is a required field."); }

At the isNull check i get an 'Object expected' runtime error. Could you help me with the script please?
 
Where have you defined your "isNull" function? If you have not defined one, that would explain the error.

If you want to test for something being null, you can use the standard "==" operator with the value "null" (not in quotes).

However, if all you want to do is see if one of a group is checked or not, you can do this:

Code:
var checked = false;
var radiolist = document.forms[0].elements['rdbTypeList'];
for (var i=0; i<=radiolist.length; i++) {
	if (radiolist[i].checked) {
		checked = true;
		break;
	}
}
if (!checked) alert("Property type is a required field.");

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks...i thought isNull was a supported function!

Now it's giving me 'checked' is null or not an object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top