tags:

views:

38

answers:

3

I want to convert this code to JavaScript code:

rdb1 = (RadioButton)DataList1.Items[i].FindControl("rdb1");

How can it be done?

A: 

Put a unique class on the radio button and then you can easily use jQuery to walk the DOM and find that control.

Here is an example of finding a control here on Stack Overflow.

Here is a tutorial of How to Get Anything You Want from a web page via jQuery.

Good luck, and hope this helps.

Chris
sorry bt i cudnt understand,,make me more clear
sumit
A: 

In JavaScript using the id attribute makes it easy to retreive a specific element since the id must be unique for all tags.

var radio1= document.getElementById("rdb1"); //this returns the element

Here is a simple tutorial on how to do other things after getting the element.

EDIT- I see you just want the selected value in javascript:

function radiochanged(){
 var radio1= document.getElementById("rdb1");
 var rdb1_value;
 for (i=0;i<radio1.length;i++) 
 { 
    if (radio1[i].checked) 
   { 
         rdb1_value = radio1[i].value; 
   } 
  } 
}

<input id="rdb1" type="radio" onClick="radiochanged()">
TStamper
A: 

OK, look at my complete code and you'll get to know what I want to do:

protected void rdb1_click(object sender, EventArgs e)
{
    string value = "";
    for (int i = 0; i < DataList1.Items.Count; i++)
    {
        RadioButton rdb1;                    
        rdb1 = (RadioButton)DataList1.Items[i].FindControl("rdb1");
        if (rdb1 != null)
        {
            if (rdb1.Checked)
            {
                HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
                value = hf.Value.ToString();
            }
        }                    
    }
    Session["Background1"] = value;            
}

I want to convert this code to JavaScript code.

sumit