Note that there are some explanatory texts on larger screens.

plurals
  1. POChange function in jQuery is firing twice on postback
    primarykey
    data
    text
    <p>I am having an issue with the change function in jQuery 1.7.1 and postbacks. Basically I need to toggle the disabled attribute of buttons depending on whether an item is selected in the dropdown. In the code I have:</p> <pre><code>&lt;input type="button" id="btnRed" value="show Red" disabled="disabled" class="spButton" /&gt; &lt;input type="button" id="btnBlue" value="show Blue" disabled="disabled" class="spButton"/&gt; &lt;input type="button" id="btnYellow" value="show Yellow" disabled="disabled" class="spButton" /&gt; </code></pre> <p>I have my asp dropdown with autopostback set to true</p> <pre><code>&lt;asp:DropDownList ID="selAccount" runat="server" onselectedindexchanged="selAccount_SelectedIndexChanged" AutoPostBack="true"&gt; &lt;asp:ListItem Value="-1"&gt;select me&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="234"&gt;234&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>and the jQuery:</p> <pre><code> $(document).ready(function () { $("#selAccount").change(function () { var selValue = $(this).val(); if (selValue == '-1') { $(".spButton").attr("disabled", "disabled"); } else { $(".spButton").removeAttr("disabled"); } }); }); </code></pre> <p>invariably, when postback occurs, the buttons remain disabled. I tested with an enabled button and it is firing twice. i have tried different approaches (bin, unbind) to no avail. I got around this issue with a hidden variable set on the SelectedIndexChanged in code-behind and interrogating the hidden variable value in jQuery. is there an issue with the change method? is there a better way to do this? any insight would be appreciated. thanks,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload