and this worked fine, on the PC, however when using the IPad, this script would not function.
07-02-2014, 01:06 PM
are 'a1' and 'p1' names or IDs?
07-02-2014, 01:28 PM
07-02-2014, 01:30 PM
sorry, 'a1' is the name i have assigned the checkbox
07-02-2014, 04:48 PM
assuming that they are both names, and that they are the first elements on the page with those names, and that in the case of both being checked you only want a1 to remain checked...
<input type="checkbox" name ="a1"/>
<input type="checkbox" name ="p1"/>
<input type="button" onclick ="checkIt()" value = "check boxes"/>
var cb1 =document.querySelector('input[name="a1"]');
var cb2 =document.querySelector('input[name="p1"]');
07-02-2014, 04:50 PM
Originally Posted by coolhandbr
I simply need a script that will either have nothing checked or only 'a1' or only 'p1' checked.
I don't understand why you are trying to make checkboxes act like radio buttons. The quoted description of the behavior you are trying to script is exactly why radio buttons exist. Example:
<input type="radio" name="choices" id="a1" value="choice 1"><label for="a1">Choice 1</label><br> <input type="radio" name="choices" id="p1" value="choice 2"><label for="p1">Choice 2</label><br> <input type="radio" name="choices" id="clearChoices" value=""><label for="clearChoices">None</label><!-- Optional. Submits nothing. Exists to let the user change his/her mind :) -->
No scripting required and it works cross-browser and cross-device. You can, however, script the buttons to do other things if you have that need.
07-03-2014, 12:38 AM
I'm with Kevin2 -- first thing I was thinking was "why not just use radio buttons" since they already do what you're trying to waste JS doing.
07-05-2014, 03:18 PM
With Kevin and deathshadow on this, radio is the way to go.
Only thing I can think of is if you are going to have multiple check boxes with various combos to select and not all options will be available depending on what is checked... Even then you can use multiple radio sets and have those selections of sub sets determined on the main set choice.