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

Get Selected Value of ComboBox in Javascript

3 Answers 2230 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 11 Feb 2014, 07:07 PM
I have figured out the long way to get the Dropdown Selected value of the combobox, but is there a shorter way than all this code

So my current method is as follows
var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>');
var sCounty = SoldCounty.get_value();
           
Then i can do something with the value.

However why does this not work

var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_value();
 
Or this
 
var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_SelectedValue();























3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Feb 2014, 03:43 AM
Hi Kevin,

Please try the following code snippet to get the SelectedItem value of RadComboBox.

ASPX:
<telerik:RadComboBox ID="ddlSoldCounty" runat="server" OnClientDropDownClosing="OnClientDropDownClosing1">
    <Items>
        <telerik:RadComboBoxItem Text="Invoice" runat="server" Value="10" />
        <telerik:RadComboBoxItem Text="Quote" runat="server" Value="5" />
    </Items>
</telerik:RadComboBox>

JavaScript:
<script type="text/javascript">
    function OnClientDropDownClosing1(sender, args) {
        var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_selectedItem().get_value();
        //or
        var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_value();
        alert(SoldCounty);
    }
</script>

Please provide your full code if it doesn't help.
Thanks,
Princy.
0
Frank
Top achievements
Rank 1
answered on 21 May 2015, 08:38 PM

I have tried this syntax but I keep getting an System.Web.HttpUnhandledException.

this line

var cik = $find('<%= myCik.ClientID %>').get_selectedItem().get_value();

always causes an the error.  anytime I have '<%=  %>' inside my javascript I get the System.Web.HttpUnhandledException.

0
Aneliya Petkova
Telerik team
answered on 26 May 2015, 07:44 AM
Hi Frank,

Using this syntax you are getting a reference to the client-side objects.The $find('<%= myCik.ClientID %>') may fail in the occasion when the control is not yet initialized. All ASP.NET Ajax controls are initialized when the page is fully loaded.

If you need further assistance, please send us a runnable example which we can inspect locally and provide you with a solution.

Regards,
Aneliya Petkova
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Frank
Top achievements
Rank 1
Aneliya Petkova
Telerik team
Share this question
or