This is a migrated thread and some comments may be shown as answers.

get ComboBox Value in javascript

3 Answers 606 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 31 Mar 2012, 11:47 PM
Hello,

   I am trying to get the combobox selected item and value in the javascript.  Does the accessing of combobox in javascript change based on the version you use?  I am using Telerik 2011.3.1305.35. 

 I have a javascript file and in that i have a function which will accept client id of the radcombobox as a parameter and now how do i get the selected index, selected item and value of that combobox? I have tried it in couple of ways but no luck.

function GetAddress(rcbCity) {
  
 // rcbCity is the clientID of the RadComboBox with ID rcbCity .
 
 how do i get the selected index,item and value here?
 
}

I am calling this GetAddress function in the user control page load.  I am adding the attributes for another button click like below
if (!IsPostBack)
 {
   btnMap.Attributes.Add(
"onClick", "GeocodeAddress('" + this.rcbCity.ClientID + "'); return false;");
}



Appreciate the help
Thanks




3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Apr 2012, 08:25 AM
Hi Jagat,

Try the following code to get selected index and value of RadComboBox.

C#:
if (!IsPostBack)
 {
   btnMap.Attributes.Add("onClick", "GeocodeAddress('" + RadComboBox.ClientID + "'); return false;");
 }

JS:
<script type="text/javascript">
function GeocodeAddress(rcbCity)
 {
   var combo = $find(rcbCity);
   alert( combo.get_selectedIndex());
   alert(combo.get_selectedItem().get_text());
   alert(combo.get_selectedItem().get_value());
 }
</script>

Hope this helps,

Thanks,
Princy.
0
Jagat
Top achievements
Rank 1
answered on 02 Apr 2012, 05:38 PM
Thanks. It worked.

Does the accessing of combobox in javascript change based on the version you use? 

0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Apr 2012, 06:23 AM
Hi Jagat,

The JavaScript for accessing the RadComboBox doesn't changes according to the version. The RadControls can be accessed in JavaScript using $find method and the ClientID of the control as follows.

JS:
var combo = $find("<%= RadComboBox1.ClientID %>");

Thanks,
Princy.
Tags
ComboBox
Asked by
Jagat
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jagat
Top achievements
Rank 1
Share this question
or