You cannot use a single <label> element to indicate two separate inputs. I would suggest linking tags with switches, since the radio button is such a small target, and the shortcut extends that target.
Select one of the radio stations that will be selected by default, possibly "$ Off". Disable the other default text box:
<div class="row-fluid control-group"> <div class="span7 pull-left"> <label class="radio" for="discount-dollars"> <input type="radio" name="discount" id="discount-dollars" value="dollars" checked="checked"> $ Off </label> <div class="input-append"> <input type="text" name="discount-dollars-amount" id="discount-dollars-amount" class="input-small dollars" placeholder="enter amount"> <span class="add-on">.00</span> </div> </div> <div class="span5"> <label class="radio" for="discount-percent"> <input type="radio" name="discount" id="discount-percent" value="percent"> % Off </label> <input type="text" name="discount-percent-amount" id="discount-percent-amount" class="input-small percent" placeholder="enter amount" disabled="disabled"> </div> </div>
Then use jQuery to do something like this:
$(function (){ $("#discount-dollars, #discount-percent").click(function (){ // get the value of this radio button ("dollars" or "percent") var value = $(this).val(); // find all text fields... $(this).closest(".control-group").find("input[type=text]") // ...and disable them... .attr("disabled", "disabled") // ...then find the text field whose class name matches // the value of this radio button ("dollars" or "percent")... .end().find("." + value) // ...and enable that text field .removeAttr("disabled") .end(); }); });
Basically, it listens for click events on both switches. When you click on one radio, it turns on the associated text field (i.e., a Text field with a CSS class name that matches the switch value) and disables the other text field. Thus, you cannot enter text in a text field unless the corresponding associated radio button is set.
source share