asp.net - Radio button in radiogroup not rendering checked when checked="checked" -
got html asp.net mvc3 (c#) application:
<div class="row-fluid"> <div class="span4"> <label for="mailprefbusi">business street</label> <input type="radio" checked="checked" class="validate[grouprequired[mailingpreference]] mailingpreference" parent_tab="tab4" id="mailprefbusi" name="mailingpreference" value="1"> </div> <div class="span4"> <label for="mailprefbusipo">business po</label> <input type="radio" class="validate[grouprequired[mailingpreference]] mailingpreference" parent_tab="tab4" id="mailprefbusipo" name="mailingpreference" value="0" disabled="disabled"> </div> <div class="span4"> <label for="mailprefhome">home</label> <input type="radio" class="validate[grouprequired[mailingpreference]] mailingpreference" parent_tab="tab4" id="mailprefhome" name="mailingpreference" value="2"> </div> </div>
but when viewing in browser, ff, ie9, ie8 , chrome, mailprefbusi radio not showing checked.
here's code generates html:
<div class="row-fluid"> @{ string busipref = ""; string popref = ""; string homepref = ""; switch (viewbag.part.mailingpreference) { case 1: busipref = "checked=\"checked\""; break; case 0: popref = "checked=\"checked\""; break; case 2: homepref = "checked=\"checked\""; break; } } <div class="span4"> <label for="mailprefbusi">business street</label> <input type="radio" value="1" name="mailingpreference" id="mailprefbusi" parent_tab="tab4" class="validate[grouprequired[mailingpreference]] mailingpreference" @html.raw(busipref) /> </div> <div class="span4"> <label for="mailprefbusipo">business po</label> <input type="radio" value="0" name="mailingpreference" id="mailprefbusipo" parent_tab="tab4" class="validate[grouprequired[mailingpreference]] mailingpreference" @html.raw(popref) /> </div> <div class="span4"> <label for="mailprefhome">home</label> <input type="radio" value="2" name="mailingpreference" id="mailprefhome" parent_tab="tab4" class="validate[grouprequired[mailingpreference]] mailingpreference" @html.raw(homepref) /> </div> </div>
also have jquery code:
if ($("#businessaddress1").val() == "") { $("#mailprefbusi").attr('checked', false); $("#mailprefbusi").attr('disabled', true); } else { $("#mailprefbusi").attr('disabled', false); if ($("#mailprefbusi").attr('checked')) { $("#mailprefbusi").attr('checked', 'checked'); } } if ($("#homeaddress1").val() == "") { $("#mailprefhome").attr('checked', false); $("#mailprefhome").attr('disabled', true); } else { $("#mailprefhome").attr('disabled', false); if ($("#mailprefhome").attr('checked')) { $("#mailprefhome").attr('checked', 'checked'); } } if ($("#poaddress1").val() == "") { $("#mailprefbusipo").attr('checked', false); $("#mailprefbusipo").attr('disabled', true); } else { $("#mailprefbusipo").attr('disabled', false); if ($("#mailprefbusipo").attr('checked')) { $("#mailprefbusipo").attr('checked', 'checked'); } }
but still not show checked. crucial part of form , radio grouping must have @ to the lowest degree 1 item checked. if user doesn't see checked, not sure value gets sent correctly, either because we've had instances user's mailingpreference modified value had empty address, no good!!
the validation beingness done using jquery validationengine.
i'm not sure what's going on here. i've searched high , low find answers come empty , seek has same result.
i had similar problem not long time ago. ended set radiobutton list initialization on client side , looked this:
$(function() { $('input[name=mailingpreference]:eq('+@(viewbag.part.mailingpreference)+')').attr('checked', 'checked'); });
asp.net html radio-button jquery-validation-engine
No comments:
Post a Comment