[jQuery] Checkboxes not working with .toggle()
I am using a checkbox to enable/disable a fieldset of input fields in a form. This toggle worls great, but the checkbox itself won't change it's state at all.
Here is the code:
<br style="font-family: courier new,monospace;">
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;"> $("#checkBox1").toggle(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> function () {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> this.attr("checked", "checked");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $("#secondaryOwner input").attr("disabled","");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $("#secondaryOwner select").attr("disabled","");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> this.attr("checked", "checked");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $("#secondaryOwner").css("color","#000");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> },</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> function () {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $("#secondaryOwner input").attr("disabled","disabled");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $("#secondaryOwner select").attr("disabled","disabled");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> this.attr("checked", "");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $("#secondaryOwner").css("color","#999");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> );</span>
</div>
Here is the HTML (though I dont think this is really the source of the problem):
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;"> <fieldset id='secondaryOwner'></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <legend></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <label for='checkBox1'>Secondary Owner</label></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <input type='checkbox' name='secondaryOwnercheckBox' value="secondaryOwnercheck" class='checkBox' id='checkBox1' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </legend></span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <div id='secondaryOwnerpersonal'></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerFirstName'>First Name</label></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerFirstName' id='secondaryOwnerFirstName' value='' /></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <label for='secondaryOwnerMI'>Middle Initial</label></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerMI' id='secondaryOwnerMI' value=' ' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerLastName'>Last Name</label></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerLastName' id='secondaryOwnerLastName' value=' ' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </div></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <div id='secondaryOwnerbusiness' style='display: none;'></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerName'>Name</label></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerName' id='secondaryOwnerName' value=' ' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </div></span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <label for='secondaryOwnerSSN' id='so_SSN'>SSN </label></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerSSN' id='so_Fein' style='display: none;'>Fein Number</label></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerSSN' id='secondaryOwnerSSN' value=' ' /></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <div id='so_individualInfo'></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <label for='secondaryOwnerLicense'>Driver's License # </label></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerLicense' id='secondaryOwnerLicense' value=' ' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerDOB'>DOB (mm/dd/yyyy)</label></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <input type='text' name='secondaryOwnerDOB' id='secondaryOwnerDOB' value=' ' /></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <label for='secondaryOwnerSex'>Gender</label></span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <select name='secondaryOwnerSex' id='secondaryOwnerSex'></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <option value='1'>Male</option></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <option value='2'>Female</option></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </select></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </div></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </fieldset></span>
</div>