I have a list of items, each item having two checkboxes; available and purchased. The item can be available without being purchased. But it cannot not be purchased without it being available. Therefore, I want the user to be able to check purchased and have 'available' auto-checked if it isn't already. This is more as a visual aid to the user feedback since when the form is submitted I can then look to see if purchased was checked and then assume available is as well(since it should be).

<input type="checkbox" name="ua0" id="ua0" value="1" onclick="ub0.checked=true">
<input type="checkbox" name="ub0" id="ub0" value="1">

This almost works as I want. However, once you click on A and then B is auto-checked, if the user unchecks B manually then unchecks A, B gets rechecked. So perhaps, is there a way to only update B when A is being checked and not unchecked?

Recommended Answers

All 5 Replies

Almost, except that also unchecks both as well. Click box A, box B checks as well. Uncheck box A, box B still stays checked unless manually done so.

In other words, box B only inherits from box A if box A is checked (not unchecked)

Member Avatar for diafol

I might of been confused with your description here, but is this what you are talking about? http://jsfiddle.net/pixelsoul/T4E2L/

I'd leave out the else bit if combos possible are:

0 0, 0 1, 1 1 (1 0 not possible)

But it works anyhow.

That's funny, Isn't that what this is doing already?

<input type="checkbox" name="ua0" id="ua0" value="1" onclick="ub0.checked=true">
<input type="checkbox" name="ub0" id="ub0" value="1">

aah.. I see what you mean now. Thanks for clearing that up Diafol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.