Skip to content

Instantly share code, notes, and snippets.

@paulmr
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save paulmr/8728969 to your computer and use it in GitHub Desktop.

Select an option

Save paulmr/8728969 to your computer and use it in GitHub Desktop.
better checkboxes
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);
}
<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