Question re: accessing web control values via client-side javascript

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';

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( + " is " + objChkInvert.checked);         // DISPLAYS True or False
    window.alert( + " is " + objChkAct_Cur.checked); // DISPLAYS True or False
    window.alert( + " is " + objradBuy_Sell.checked);    // UNDEFINED !!!

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 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>
<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>

I can't determine which radio button was selected - "1" or "2" ??? What am I missing here ???


1/11/2006 8:30:50 PM 24353 articles. 2 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 34
Get it on Google Play
Get it on Apple App Store

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.


Peter Brunone
Do the impossible, and go home early.
1/11/2006 9:34:14 PM
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.


1/11/2006 11:18:38 PM
What's the error?

Peter Brunone
Do the impossible, and go home early.
1/12/2006 2:16:15 AM
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;

1/12/2006 6:02:32 PM

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
Do the impossible, and go home early.
1/12/2006 6:07:13 PM

Similar Artilces:

Accessing server-side control in client-side javascript function; on Content page
I am trying to set an asp:textbox value in the Client side javascript function. It works fine on the standalone page. But when i try to do this the Content page, it’s giving the follwoing error message. document.getElementByID[...] is null of not an object  Any idea? Thanks, Riz   Hi, are you using ClientID property of that server control, to get its ID (which is rendered at the client and can be used with document.getElementById )?Thanks,Teemu KeiskiFinland, EU Thank you my problem is solved....

Problem accessing server side array values from javascript client side function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>; First of all, you can't mix server-side and client-side code. The reason is that the protocol that is used to communicate betwee...

Problem accessing server side array values from client side javascript function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>;...

Please help : question on how to reference web controls from client-side Javascript .
Folks,  I have some simple Javascript here that needs to reference not only aCheckBox object being passed as a parameter, but also various otherfields on my web page. My main question is HOW do I access/manipulate controls withclient-side script ? I know how to access the value of the Checkbox because I pass it to myjavascript function like this : QuoteConv(this) . However, since Asp2.0 renames all the ID properties of my web controls, what's the bestway to reference all the various controls (i.e. html TextBox, checkbox,radio, etc) ???Here's the beginning of my aspx page with...

How to access the properties and methods of the ActiveX control on the client side in Web Form using javascript or vbscript
Hi All, I have looked almost every where for this, and I'll be really appreciated if someone can help me with this. I found a article in MS KB article, #317392, but it is not extactly what I wanted. How do you reference an ActiveX control's methods and properties with javascript in the ASPX? Following is what I have. Some how the following line in the btnclick() does not seems to be working. AlarmCtl.StartTimer() I have done this with just .HTML and it works just fine. Can any one help. Thanks in advance. //===========================...

List of client side function of extenders and controls for client side
Hello All,I am using AJAX control toolkit for my current project. Now I need to find out what client side functions I can call on an extender. Lets say I am using a PopControlExtender. Now I want to show the popup from a JS funtions.If I can do a guess then it would be something like this$find('ppce').show();From where I can find what client side functions I can call on those extensders. This is really a frusterating thing. I learn about extenders only from Learn tutorials, no help here and there. Can anybody please tell me where are documentations about all the extenders in the tool...

How to access dynamically Html controls (client side controls) using C# server side scripts
Folks,I have problem try to to access dynamically Html controls (client side controls) using C# server side scripts. Please give me helps.     The error is as follows Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error: Line 79: { Line 80: Control c = Page.FindControl("ddlTC" + i); Line 81: ((DropDownList)c).DataSource = mdt; Line 82: ((DropDownList)c).DataTextField = "ClassID"; Line 83: ((DropDownList)c).DataValueField = "Course"; My aspx page source codes: ...<...

Accessing values on the server for controls whose values were changed client-side
Let's say that I have two server controls, a label and a textbox: <asp:Label ID="Label1" runat="server" Text="Old value"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Text="Old value"></asp:TextBox> Then I run some client-side code that changes their values: document.getElementById('Label1').innerHTML = 'New value'; document.getElementById('TextBox1').value = 'New value'; In the browser, they both visually have the value "New value".  Howev...

How to access all the methods of server controls and infragistics controls from client-side javascript.
I have some web controls on my page, which i want to manipulate without going to the server, that is, from a client-side javascript. I know how to call them with the documents.forms.... but i do not know how to call their methods. For the text box, the method to manipulate it is 'value'. It's a property i think. for the html <select> it is the 'options' array. But for the others, I dont know.My question is the following:I have an infragistics control: the UltraWebTree.This is its code in html: <ignav:ultrawebtree id="UltraWebTree1" style="Z-INDEX: 108; LEFT: 352p...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Accessing server-side Datatable object from client-side javascript?
I am working on a control  that generates 2D charts (line,bar,pie,etc) using VML (for now) to draw the charts client-side. I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side.  I am currently using a Sys.Data.Datable on the client side as test data (building the table manually in javascript) and it works fine but I cannot figure how to pass a datatable from the server to the control extension behavior? I have read/seen code on the forums on how to do this using a web-service but I am really looking a...

How to take value from client side control from server side code?
Hi all, I would like to know that, how to access client side control in server side code? Here is an example.. I am having the textBox in client side like <input type="text" id="textBoxUsername" name="textBoxUsername"/> I need to take the value from this textBox in button click event which is server side code. private void buttonShow(object sender, System.EventArgs e) { //I need to access this textBox here. } How to do that? Thanks R. eswaran. hi you need to make it run at server. <input type="text" id="textBoxUsername"...

Accessing Wizard controls from client-side Javascript
Hello, all.  Thank you in advance for taking the time to read this.  I know it is of questionable relevance given that the Wizard control is not an AJAX toolbox component, but since the Wizard is more useless without AJAX, I am hoping it is close enough to topic.  I am dealing with a Viewstate issue that is forcing me to use ScriptingServices for most of my async communications in order to keep round-trip bandwidth manageable.  I want to be able to validate entries made on a long wizard both on-the-fly and at-once.  But using ScriptServices, I need to access the val...

diasbling controls via javascript client-side
hi,   is it possible to disable a complete <div> by using a client-side javascript ?   if so how ?  at the moment i am having to make the <div> visible/non-visible. I would rather just disable it so that the  user can see that there is another option available if they choose. cheers. Ya, you can. Give an ID for your DIV ( is it <asp:Panel> ?). Then in your JavaScript, document.getElementById("MyDIV").disabled = true;Alternatively, you can enable/disable the DIV (Panel) using ASP.NET instead.Alvin ChooiMicrosoft ASP.NET™ Enthusiast v1.1...

Web resources about - Question re: accessing web control values via client-side javascript -

Client-side scripting - Wikipedia, the free encyclopedia
... different and changing content depending on user input, environmental conditions (such as the time of day), or other variables. Client-side ...

Senior Search Manager - Client Side!!
... strategy insight for senior IT management - resources to understand and leverage information technology. Senior Search Manager - Client Side ...

Account Manager - Client Side - Previous Agency Experience Welcome!!
Computerworld Australia is the leading source of technology news, analysis and tools for IT decision makers, managers and professionals.

Media Sales Executive - Client Side!!
Technology news and reviews for business and home.

PPC Paid Search Manager - CLIENT SIDE
Defining Technology for Australia's IT Leaders. PPC Paid Search Manager - SEM - **CLIENT SIDE** Sydney CBD Location Client side!! SEM/PPC/Paid ...

How Basecamp Next got to be so damn fast without using much client-side UI
When we started working on Basecamp Next last year, we had much internal debate about whether we should evolve the existing code base or rewrite ...

Seven Tips for Pitching From the Client's Side of the Table
I had a chance to sit on the other side of the pitch table. Here is what I learned.

Client-side coding: How to prevent malicious use?
Applications that run on a user-controlled device cannot be perfectly protected.

The client side
... regarding the professionals you seek to assist. Even better if you possess that understanding yourself, having worked on the client side. I'm ...

Ecommerce traffic being hijacked by client side malware
According to new research 15 to 30 percent of eCommerce site visitors are infected with Client Side Injected Malware (CSIM) that causes them ...

Resources last updated: 1/4/2016 2:40:57 PM