This block of variables gets generated dynamically from my _PreRender event of my formView :
<SCRIPT Language='JavaScript'>
var chkInvertAliasID = 'ctl00_ContentPlaceHolder1_FormView1_chkEditInvert';
var chkAct_CurAliasID = 'ctl00_ContentPlaceHolder1_FormView1_chkEditAct_Cur';
var radBuy_SellAliasID = 'ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell';
</SCRIPT>
Now on the client-side I get a handle to above-declared var's :
function QuoteConvention(obj) {
var objChkInvert = document.getElementById(chkInvertAliasID);
var objChkAct_Cur = document.getElementById(chkAct_CurAliasID);
var objradBuy_Sell = document.getElementById(radBuy_SellAliasID);
window.alert(objChkInvert.id + " is " + objChkInvert.checked); // DISPLAYS True or False
window.alert(objChkAct_Cur.id + " is " + objChkAct_Cur.checked); // DISPLAYS True or False
window.alert(objradBuy_Sell.id + " is " + objradBuy_Sell.checked); // UNDEFINED !!!
return;
}
No problem getting the selected checkbox value, but my problem is accessing which radio button was selected on the web page (i.e. objradBuy_Sell.value, objradBuy_Sell.checked ???).
Of course this is how asp.net 2.0 is actually rendering the page on cliend-side :
<table id="ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell" onClick="QuoteConv(this);">
<td><input id="ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell_0" type="radio" name="ctl00$ContentPlaceHolder1$FormView1$radioEditBuySell" value="1" />
<label for="ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell_0">Buy</label></td>
</tr><tr>
<td>
<input id="ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell_1" type="radio" name="ctl00$ContentPlaceHolder1$FormView1$radioEditBuySell" value="2" checked="checked" />
<label for="ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell_1">Sell</label>
</td>
</tr>
</table>
I can't determine which radio button was selected - "1" or "2" ??? What am I missing here ???
Thanks,
Bob
![]() |
0 |
![]() |
Hi Bob,
This can be a little confusing, especially with all those crazy NamingContainer prefixes. Basically, you can take one of two approaches:
1) Get the ClientID of one of the radio buttons, and then (client-side) get the name attribute. Once you have that, you can call document.formName[nameofradiobutton] and get an array of all radio buttons with that name. You can then loop through that array to see which one's checked attribute is set to true.
2) The other way -- since objradBuy_Sell is actually a table, not a radio button -- would be to call objradBuy_Sell.getElementsByTagName("INPUT") which will return a collection of all radio button inside (assuming this is a RadioButtonList). Then you just loop through and test easy element for checked, as you would in the previous approach.
HTH,
Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
![]() |
0 |
![]() |
I've got this so far in function QuoteConvention() :
....
var objradBuy_Sell = document.getElementById(radBuy_SellAliasID);
....
radioDom = objradBuy_Sell.getElementsByTagName("INPUT");
window.alert(radioDom.length); // THIS DISPLAYS "2"
Great so far. I can see that I have an object with "2" items, but how do I walk through radioDom ? I've tried radioDom.elements[0].value but I get an error the page.
Thanks,
Bob
![]() |
0 |
![]() |
What's the error?
Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
![]() |
0 |
![]() |
IE just says "error on page" down in the lower left-hand corner of the browser.
Maybe I'll takes someone's suggestion to make two seperate radio buttons instead of radiobuttonList.
Here's my entire js function :
function QuoteConvention(obj) {
// We dynamically generated our AliasID vars from code-behind
var objdrpCur1 = document.getElementById(drpCur1AliasID);
var objdrpCur2 = document.getElementById(drpCur2AliasID);
var objradBuy_Sell = document.getElementById(radBuy_SellAliasID);
var objChkInvert = document.getElementById(chkInvertAliasID); /
var objChkAct_Cur = document.getElementById(chkAct_CurAliasID);
var objQuoteConv1 = document.getElementById(txtQuoteConv1ID);
var objQuoteConv2 = document.getElementById(txtQuoteConv2ID);
var objCur1Amt = document.getElementById(txtQuoteCur1AmtID);
var objCur2Amt = document.getElementById(txtQuoteCur2AmtID);
var objhidBuy_Sell = document.getElementById("hidBuySell"); // register in _PreRender event
var objhidAmount = document.getElementById("hidAmount");
var objhidRate = document.getElementById("hidRate");
var nAmount = objhidAmount.value;
var nRate = objhidRate.value;
var nCalcAmount = nAmount * nRate;
radioDom = objradBuy_Sell.getElementsByTagName("INPUT");
window.alert(radioDom.length); // Okay - displays "2"
window.alert( radioDom.elements[1].value) ); // "ERROR ON PAGE" in IE window
if (objChkInvert.checked == true) { // invert the currency pair
objQuoteConv1.value = objdrpCur2.value;
objQuoteConv2.value = objdrpCur1.value;
} else {
objQuoteConv1.value = objdrpCur1.value;
objQuoteConv2.value = objdrpCur2.value;
}
return;
}
![]() |
0 |
![]() |
What message do you get when you double-click the little yellow error icon next to the "Error on page" message in the lower-left-hand corner of the browser?
Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
![]() |
0 |
![]() |