Last active
August 29, 2015 13:55
-
-
Save paulmr/8728969 to your computer and use it in GitHub Desktop.
better checkboxes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function betterbox() { | |
| var boxes = $(".betterbox"); | |
| function reconcile() { | |
| var e = $(this); | |
| $("#" + e.attr("data-targid")).val(e.is(":checked") ? | |
| e.attr("data-yesval") : e.attr("data-noval")); | |
| } | |
| boxes.each(reconcile); | |
| // locate and save the target | |
| boxes.change(reconcile); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p> | |
| <input | |
| class="betterbox" | |
| data-targid="testval" | |
| data-yesval="TRUE" | |
| data-noval="FALSE" | |
| type="checkbox" | |
| id="checktest" | |
| name="checktest" | |
| /> | |
| <input | |
| type="checkbox" | |
| class="betterbox" | |
| data-targid="testval" | |
| data-yesval="cheese" | |
| data-noval="yoghurt" | |
| checked="yes" | |
| /> | |
| </p> | |
| <p> | |
| <input type="text" id="testval" name="testval"/> | |
| </p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment