Two options
click on checkbox 1 then shows and selects 2
click on paragraph 2 then shows abcde
option 1 works fine
where am i going wrong on option 2
I would like it to select abcd and one of e
This is the jquery
$(document).ready(function() {
$('.child').hide();
$(".parent").click(function() {
$('#form' + $(this).attr('id')).toggle();
$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
});
});
This is the html
<fieldset>
<p>
<label for="5">1</label>
<input type="checkbox" name="1" id="5" value="360" class="parent" />$360
</p>
<p id="form5" class="child">
<label for="6">2</label>
<input type="checkbox" name="2" id="6" value="2" />$180
</p>
</fieldset>
<fieldset>
<p name="4" id="1st" class="parent">a</p>
<p id="form1st" class="child">
<label for="7">a</label>
<input type="checkbox" name="a" id="7" value="25" />$25
<br />
<label for="8">b</label>
<input type="checkbox" name="b" id="8" value="18" />$18
<br />
<label for="9">c</label>
<input type="checkbox" name="c" id="9" value="18" />$18
<br />
<label for="10">d</label>
<input type="checkbox" name="d" id="10" value="18" />$18
<br />
<label for="11">e</label>
<span id="11">
<input type="checkbox" name="?" value="18" />e1
<input type="checkbox" name="?" value="36" />e2
<input type="checkbox" name="?" value="54" />e3
<input type="checkbox" name="?" value="72" />e4
<input type="checkbox" name="?" value="90" />e5
<input type="checkbox" name="?" value="100" />e6
<input type="checkbox" name="?" value="" />other
</span>
</p>
</fieldset>
And a demo
Here is your problem.
this.checkedis undefined in ‘option 2’It works when you click on
because it is a checkbox and it has
chechedattribute. But when you click onwith ‘this’ you refer the
<p>element which has nocheckedattribute– Update
jsfiddle updated example