3 posts, 0 answers
  1. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 10 Jul 2013 Link to this post

    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


        var combo = $('#cmb_Married');

        if(combo.get_selectedItem().get_Text() == "Yes") {

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Jul 2013 Link to this post

    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().

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

  3. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 11 Jul 2013 Link to this post

    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.

Back to Top