get ComboBox Value in javascript

4 posts, 2 answers
  1. Jagat
    Jagat avatar
    151 posts
    Member since:
    Jan 2011

    Posted 31 Mar 2012 Link to this post

    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




  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2012 Link to this post

    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.
  3. Jagat
    Jagat avatar
    151 posts
    Member since:
    Jan 2011

    Posted 02 Apr 2012 Link to this post

    Thanks. It worked.

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

  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2012 Link to this post

    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.
Back to Top