locked
set Index of ajaxcombox via jquery ! RRS feed

  • Question

  • User547991737 posted

    Hello Experts 

    I have a combobox in a page , after loading a page i am fatching preivously selcted values from Cookies via jquery 
    and i want to select that value in combobox .


    actualCount = -1;
    //get all comboBoxes
    var inputCount3 = parseInt($.cookie("cookieInputCount3"));
    var inputCSV3 = $.cookie("cookieInputCSV3");
    if (inputCount3 > 0 && inputCSV3 != '') {
    actualCount = $("#innerPopup .ajax__combobox_textboxcontainer").find('input').length;
    if (actualCount == inputCount3) {
    var arr3 = inputCSV3.split('Ø'); //Alt +0216
    $("#innerPopup .ajax__combobox_textboxcontainer").find(":input").each(function (index) {
    // console.log(arr3[index]);
    debugger;


    $(this).val(arr3[index]);

    //set hidden field
    $(this).parent().parent().parent().parent().parent().find('input:hidden').val(2)


    });
    }
    }




    I tried to addvalue in textbox as well as hidden field but nothing is happeninI have no luck so far

    Please help! 

    Friday, March 7, 2014 6:31 AM

Answers

  • User-417640953 posted

    Hi arry.net,

    Thanks for your post.

    From your description, I see you want to set the index of ajax control ComboBox by jquery.

    For this issue, I made a demo below, please check it.

    <head runat="server">
        <title></title>
        <script src="//code.jquery.com/jquery-1.9.1.js"></script>
        <script defer="defer">
         function SetIndex(index) {
               
               $("#ComboBox1_ComboBox1_TextBox").val($("#ComboBox1_ComboBox1_OptionList").find("li").eq(index).html());
               $("#ComboBox1_ComboBox1_HiddenField").val(index);
    
               //  alert($("#ComboBox1_ComboBox1_TextBox").val()) 
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <asp:ComboBox  ID="ComboBox1" runat="server"  DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend" >
                <asp:ListItem Selected="True" Text="one" Value="one"></asp:ListItem>
                <asp:ListItem  Text="two" Value="two"></asp:ListItem>
                <asp:ListItem  Text="three" Value="three"></asp:ListItem>
                <asp:ListItem  Text="four" Value="four"></asp:ListItem>
            </asp:ComboBox>
            <input id="Button1" type="button" value="Set Index" onclick="SetIndex(2)" />
        </div>
        </form>
    </body>  

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 10, 2014 5:51 AM

All replies

  • User1208776063 posted

    Instead of trying to find the hidden field using nested parent() node, try finding the control using ID. 

    jQuery('#hiddenfieldId or dynamic variable').val('something here')

    you may need to use debugger tools to see how you can find the Id of the hidden control

    Friday, March 7, 2014 7:46 AM
  • User-417640953 posted

    Hi arry.net,

    Thanks for your post.

    From your description, I see you want to set the index of ajax control ComboBox by jquery.

    For this issue, I made a demo below, please check it.

    <head runat="server">
        <title></title>
        <script src="//code.jquery.com/jquery-1.9.1.js"></script>
        <script defer="defer">
         function SetIndex(index) {
               
               $("#ComboBox1_ComboBox1_TextBox").val($("#ComboBox1_ComboBox1_OptionList").find("li").eq(index).html());
               $("#ComboBox1_ComboBox1_HiddenField").val(index);
    
               //  alert($("#ComboBox1_ComboBox1_TextBox").val()) 
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <asp:ComboBox  ID="ComboBox1" runat="server"  DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend" >
                <asp:ListItem Selected="True" Text="one" Value="one"></asp:ListItem>
                <asp:ListItem  Text="two" Value="two"></asp:ListItem>
                <asp:ListItem  Text="three" Value="three"></asp:ListItem>
                <asp:ListItem  Text="four" Value="four"></asp:ListItem>
            </asp:ComboBox>
            <input id="Button1" type="button" value="Set Index" onclick="SetIndex(2)" />
        </div>
        </form>
    </body>  

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 10, 2014 5:51 AM