Note that there are some explanatory texts on larger screens.

plurals
  1. POcheckbox won't enable/disable until control loses focus
    primarykey
    data
    text
    <p>I’m working on an ASP.net page that displays a datagrid with a checkbox and a dropdownlist in each row. To continue on to the next step, each row must either have a check or an option selected, but never both.</p> <p>I am attempting to disable the dropdownlist if the checkbox is checked, and to disable the checkbox if any option except “Select a Reason” is selected. I’m trying to do everything client side, using jquery 1.4 (I know its old, but that’s the UI leads decision). </p> <p><strong>My code works fine in Chrome and IE8, but when I use Firefox 16 the checkbox does not disable upon selection change, until the user clicks outside the grid. Then the box disables. I want to get rid of the extra click.</strong></p> <p>Here is the grid markup:</p> <pre><code>&lt;asp:GridView ID="gvApps" runat="server" CssClass="sGrid" HorizontalAlign="Center" AutoGenerateColumns="False" EmptyDataText="No Data" PageSize="3" ShowHeaderWhenEmpty="True" &gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Select"&gt; &lt;itemtemplate&gt; &lt;asp:checkbox id = "gvCheckbox" runat="server" onclick="RowCheckChanged(this)" /&gt; &lt;/itemtemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField datafield="FiscalYear" HeaderText="Year" /&gt; &lt;asp:TemplateField HeaderText="Reason"&gt; &lt;itemtemplate&gt; &lt;asp:DropDownList id = "ddlReason" Viewstate="true" DataSource="&lt;%# ReasonsList %&gt;" runat="server" /&gt; &lt;/itemtemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;emptydatatemplate&gt; &lt;p class="norecords"&gt;There are currently no Records &lt;/p&gt; &lt;/emptydatatemplate&gt; &lt;/asp:GridView&gt; </code></pre> <p>Here is my OnReady:</p> <pre><code> &lt;script type="text/javascript"&gt; $(function () { $("select").change(function () { $(IndexChanged(this)); }); }) &lt;/script&gt; </code></pre> <p>Here are the IndexChanged and RowCheckChanged functions:</p> <pre><code>&lt;script type="text/javascript"&gt; function RowCheckChanged(objRef) { var row = objRef.parentNode.parentNode; if (objRef.checked) { $(row).find("select").attr("selectedIndex", 0); $(row).find("select")[0].disabled = true; } else { $(row).find("select")[0].disabled = false; } } function IndexChanged(objRef) { //toggle chkb enabled-ness var row = objRef.parentNode.parentNode; if ($(row).find("select option:selected").text() == "Select a Reason") { //both objects should be enabled $(row).find(":checkbox").attr("disabled", false); } else { //a selection has been made, disable checkbox. $(row).find(":checkbox").attr("disabled", true); } } &lt;/script&gt; </code></pre> <p>Any Ideas?</p> <p>Edit: here is the markup generated by the grid client side (per firebug):</p> <pre><code>&lt;select id="MainContent_wiz_IntraAppYears1_gvApps_ddlReason_0" viewstate="true" name="ctl00$MainContent$wiz$IntraAppYears1$gvApps$ctl02$ddlReason" disabled=""&gt; &lt;option value="Select a Reason" selected="selected"&gt;Select a Reason&lt;/option&gt; &lt;option value="Tax Exempt"&gt;Tax Exempt&lt;/option&gt; &lt;option value="Out of Business"&gt;Out of Business&lt;/option&gt; &lt;option value="Worked under Another Authority"&gt;Worked under Another Authority&lt;/option&gt; &lt;/select&gt; </code></pre>
    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.
    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