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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass radio button object to a function 1

Status
Not open for further replies.

akgta

Programmer
Jul 18, 2007
42
CA
i got the following code to test whether a radio button has value selected or not.

also lets say there is a radio group 'gender' in html form and there is an onclick="has_value();" event on the submit button, then the question is how can we call this function to pass the radio button meaning what would be the arguments sent?

Code:
function has_value(obj, obj_type) 
{
  if (obj_type == 'radio')
  {
	if (obj[0]) 
	{
		for (i=0; i < obj.length; i++) 
		{
			if (obj[i].checked)
				return true;
		}
	} 
	else 
	{
		return (obj.checked);
	}
	return false;
  }
}

Thanks in advance.
 
To pass the radio button element to the function, pass "this" if passing from the radio button itself.

If not from the radio button itself, then access it through the form's "elements" collection.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top