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

radio buttons and getelementbyid 1

Status
Not open for further replies.

DeepBlerg

Technical User
Joined
Jan 13, 2001
Messages
224
Location
AU
Hi,

I have some radio buttons and a normal button and on the onClick of the button I have a window.open() and I would like the value of the selected radio button to be parsed to that function.

So far it sorta works however because all the ids of the radio buttons are the same it only gets the value of the first radio button and not the checked one.

The button's onClick is:
window.open('options.php?sid=' + document.getElementById('radiobuttons').value, '', 'width=500,height=400')
 
Why are all the IDs the same? An ID should be unique for each object. Radio button names should be the same to form a group, but the IDs should be unique.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
If the ID's are all the same then my onClick action wouldnt work. I need to refer to the radio button group, because I don't know which radio button the user will check.
 
document.YourFormName.YourRadioButtonName.value will return the value of the selected radio button.

You don't need to use IDs at all.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
I tried that and it returns 'undefined'. Possibly because the form has yet to be submitted?
 
This function should give you some idea what to do if you look it over.
Code:
function valueOfCheckedRadio( groupname ) {

	var radio_group = document.getElementsByName( groupname );

	for( i=0; i < radio_group.length; i++ ) {

		if( radio_group[ i ].checked ) {
	
			return radio_group[ i ].value;
		}
	}
}

HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top