I am trying to use jquery’s parents/siblings to find particular input elements but I cannot seem to get this right.
I have the following HTML:
<div id="ExtrasOptions">
<div class="selectItem">
<div class="selectPrice"><span>Qty: <input name="qty" type="text" value="0" maxlength="2" id="qty" class="AccessoryQuantity" /></span></div>
<div class="selectIt"><span><input name="extraselected" type="checkbox" id="extraselected" value="9" /><label for="extrasID">Add this</label></span></div>
</div>
<div class="selectItem">
<div class="selectPrice"><span>Qty: <input name="qty2" type="text" value="0" maxlength="2" id="qty2" class="AccessoryQuantity" /></span></div>
<div class="selectIt"><span><input name="extraselected2" type="checkbox" id="extraselected2" value="9" /><label for="extrasID">Add this</label></span></div>
</div>
</div>
Q1: When someone checked a checkbox I want the textbox within the same div.selectItem to have a ‘1’ put into it. If they uncheck the checkbox I want the value to be removed.
Q2: I also want the checkbox to be checked if a value is entered into the textbox and unchecked if the textbox is blank.
Thanks for your help.
Something like this should work. (Not tested for precise syntax, but the algorithm is solid.)