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

Check Radio button from parameter

Status
Not open for further replies.

softwarescience

Programmer
Dec 7, 2001
71
GB
Hello

I seem to have hit a mind-bendingly awkward problem using GetElementsByName to get a radio button group and select a particular item.

Following is a portion of the code I am trying to make work.
Code:
function doDataPopup(sArgs, sType) {
	var RetVal;
	var oObj;

	RetVal = window.showModalDialog("fraPopup.aspx", "", "center: Yes; help: No; resizable: Yes; status: No;");

	switch (sType) {
	case "Radio" :
		alert(sArgs);
		oObj = document.getElementsByName(sArgs);
		if (oObj != null){
                        //never gets in here
			alert('Found obj');
			oObj[RetVal].checked=true;
		}

		if (RetVal=='1'){
			alert(sArgs + '_1');
			oObj = document.getElementById(sArgs + '_1');
			if (oObj != null){
                        //never gets in here
				alert('Found obj 1');
				oObj.checked = true;
			}
		}else{
			alert(sArgs + '_0');
			oObj = document.getElementById(sArgs + '_0');
			if (oObj != null){
                        //never gets in here
				alert('Found obj 0');
				oObj.checked = true;
			}
		}
		break; 
	default :
		if (RetVal != null){
			oObj = document.getElementById(sArgs);
			if (oObj != null){
				oObj.value = RetVal;
			}
		}
	} 
}

As shown, I pass the element name (I've tried id as well) to a modal popup which then returns a value.
I have found absolutely no way of ensuring that the correct radio button is checked after the popup window.

Surely it can't be that difficult to programmatically select an existing radio button from a group.

Any suggestions as to what I'm doing wrong would be greatly appreciated.
 
>>case "Radio"

i think it should be "radio" (it may be case sensitive)...

Known is handfull, Unknown is worldfull
 
Hello

I'm passing in two strings, the element name/id (i've tried both) to 'sArgs' and the element type to 'sType'.
So both parameters are simple strings.
My radio buttons have the following structure (in form1);
Code:
<input id="uscQryColz5_rblBoolean_0" type="radio" name="uscQryColz5:rblBoolean" value="0" /<input id="uscQryColz5_rblBoolean_1" type="radio" name="uscQryColz5:rblBoolean" value="1" /

I've tried to pass in both 'form1.uscQryColz5_rblBoolean' and then used getElementById by concatenating the '_0' or '_1' to get the correct radio button, also,
I passed in 'form1.uscQryColz5:rblBoolean' and tried to use the object array to select the correct value.

Re: vbkris, sType is a string that I pass in myself so the case is correct in this instance

Many thanks
 
Re: my last post the code part seems to be missing the radio buttons closing tags, but I can assure you they are there!
 

AFAIK, colons are not valid in names or IDs. Try removing this, or replacing it with a valid character (a-z, A-Z, 0-9, _ ).

Hope this helps,
Dan
 
Hello softwarescience,

Are you sure fraPopup.aspx is set up so that when the modaldialogue window closed the RetVal reflects the data you want? That is the main thing to have to make sure so that all the rest perform. Why not alert RetVal to see what it gives?

regards - tsuji
 
Re: BillyRayPreachersSon
That's what I thought! However, this is asp.net rendering controls derived from the RedioButtonList (within a usercontrol). I have found no simple way of controlling the name. I specified the id (which is rendering as expected) but the name is auto generated.

Re: tsuji
Yep, it definately returns the correct values. I trimmed the code I've shown for brevity.

My issue is that the following code,
Code:
oObj = document.getElementsByName(sArgs);
OR
oObj = document.getElementById(sArgs + '_0');
never returns an oObj, is always null.
 
softwarescience,

Maybe the browser is not supporting them?! Else, that's curious. Are those elements (radio group) dynamic? (looks like, with you code-generated id/name...)

- tsuji
 

Personally, I'd ask in the .Net forums on how to remove the colon from the name. While I cannot be 100% sure that that is the cause of your problem, being that it is very much against the specs, there's a good chance.

Dan
 
After a bit more toing and froing I eventually found the problem.
The 'getElementById' method does work using 'uscQryColz5_rblBoolean_0', the problem was that for some reason I'd started appending 'Form1.' to it.
Apparently 'getElementById' has no regard for the form level.

Thanks for all your help.
 
Hello BillyRayPreachersSon,

Your repeated observations on the naming convention of id intrigue me to check out w3c recommendation. On [6. HTML data types], I read this
w3c6.2-SGML basic types said:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
So I would say the id's mentioned are w3c complied?

regards - tsuji
 

Do you know - the last time I checked the specs, I could have sworm that I didn't see colon in there... Then again, maybe that was the HTML 3.2 specs! Thanks for pointing that out - I'll remember that one now!

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top