jquery - Why does input type radio does not work without clicking on it? -
i'm using bootstrap , have radio button grouping works weird. here markup:
<div class="btn-group custom-btn-group" data-toggle="buttons"> <label class="btn btn-default active"> <input type="radio" class="form-control" name="feature_enabled" value="1"> enabled </label> <label class="btn btn-default"> <input type="radio" class="form-control" name="feature_enabled" value="0"> disabled </label> </div>
so can see "enabled" button enabled upon page loaded. if don't click on "enabled" button , submit form variable feature_enabled
not nowadays if do, is. i'm using jquery's serialize()
function collect form data. when click on radio input can see (in developer toolbar) no "checked" or "selected" attributes added html node. furthermore if come in $('input[type=radio]:checked').val()
got undefined
after click on button got value.
why happens?
update updated names of radio buttons because said should have same name. in workspace have. 'bug' got in when altered html markup create question.
update 2 ok, i can add together "checked" attribute radio button , "active" class makes input pressed. but! check bootstrap site inputs here or here! open developer toolbar f12 , see when click either of radio inputs no "checked" attribute added html source. , site saves value of featue_enabled
when click on before saving , input node not "checked" attribute. alter can observe 'active' class goes clicked node , leaves other. (and again, posting form working without "checked" attribute!) think interesting case , know why happening!
try
$('input[type=radio]').attr('checked','true');
jquery html twitter-bootstrap-3 radio-button
No comments:
Post a Comment