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

RadComboBox.get_selectedItem().get_Text()

2 Answers 58 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mych
Top achievements
Rank 1
Mych asked on 10 Jul 2013, 05:28 PM

I have an asp.net page where I have declared static id's in the page declaration

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb"
Inherits="Test" ClientIDMode="Static" %>

On the page I have a combobox. ID=cmb_Marriage

At the end of my page I have the following function

 

$(window).load(function(){
    var combo = $('#cmb_Married');

    if(combo.get_selectedItem().get_Text() == "Yes") {
      $('#div_Married').show("slow");
   
}
}

When I run the page I get an error on the third line of the above code. Error = Microsoft JScript runtime error: Object doesn't support this property or method.

I have tried changing first line to var combo = $find("<%= cmb_Married.ClientID %>");

but still get the same error.

Any ideas why?

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 11 Jul 2013, 06:14 AM
Hi Mych,

Please have a look at the following code I tried which works fine as expected. Also JavaScript is case sensitive, so you need to give get_text() instead of get_Text().

JavaScript:
<script type="text/javascript">
    $(window).load(function () {
        var combo = $find("<%= cmb_Marriage.ClientID %>");
        if (combo.get_selectedItem().get_text() == "Yes") {
            $("div_Married").show("slow");
        }
    });
</script>

Thanks,
Shinu.
0
Mych
Top achievements
Rank 1
answered on 11 Jul 2013, 01:27 PM
Shinu, Thanks... I did have get_Text in my code it just mis-typed it in the example I gave. The issue I had was I have a page with 18 comboboxes. The controls were not fully formed when my window onload function ran and thus it could not find the object.

I have fixed this by delaying the script.... not sure if this will have an impact in production but it seems to work well on my dev setup.

My fix is....
setTimeout(function () { SetDivs() }, 3000);
where SetDivs() contains the code as shown above plus similar code to check anothe 3 other combos and show optional divs if combo is set to a specific value.

Tags
ComboBox
Asked by
Mych
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Mych
Top achievements
Rank 1
Share this question
or