Skip to content

Instantly share code, notes, and snippets.

@bryanbibat
Created June 9, 2011 06:01
Show Gist options
  • Save bryanbibat/1016150 to your computer and use it in GitHub Desktop.
Save bryanbibat/1016150 to your computer and use it in GitHub Desktop.
jQuery toggle
$("input[name='ballot[city]']").click(function() {
if ($("input[name='ballot[city]']:checked").val() == "Other") {
$("#ballot_other").removeAttr("disabled");
} else {
$("#ballot_other").attr("disabled", "disabled");
}
});
$("input[name='ballot[city]']").click(function() {
if ($("input[name='ballot[city]']:checked").val() == "Other") {
// enable text box
} else {
// disable text box
}
});
<div class="field">
<input id="ballot_city_quezon_city" name="ballot[city]" type="radio" value="Quezon City" />
<label for="ballot_city_quezon_city">Quezon City</label>
</div>
<div class="field">
<input id="ballot_city_manila" name="ballot[city]" type="radio" value="Manila" />
<label for="ballot_city_manila">Manila</label>
</div>
...
</div>
<div class="field">
<input id="ballot_city_other" name="ballot[city]" type="radio" value="Other" />
<label for="ballot_city_other">Other, please specify</label><br/>
<input disabled="disabled" id="ballot_other" name="ballot[other]" size="30" type="text" />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment