How to set radio button selected value in javascript:
HTML Code :
<input type="radio" name="RBLExperienceApplicable" class="radio" value="1" >
<input type="radio" name="RBLExperienceApplicable" class="radio" value="0" >
<input type="radio" name="RBLExperienceApplicable2" class="radio" value="1" >
<input type="radio" name="RBLExperienceApplicable2" class="radio" value="0" >
ASPX Code
<asp:RadioButtonList ID="RBLExperienceApplicable" runat="server" class="radio" RepeatDirection="Horizontal" EnableViewState="false">
<asp:ListItem Value="1" Text="Yes "></asp:ListItem>
<asp:ListItem Value="0" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RBLExperienceApplicable2" runat="server" class="radio" RepeatDirection="Horizontal" EnableViewState="false">
<asp:ListItem Value="1" Text="Yes "></asp:ListItem>
<asp:ListItem Value="0" Text="No"></asp:ListItem>
</asp:RadioButtonList>
// Some Code Fetch from db
// Based on db value script block will execute
<script type="text/javascript">
RadionButtonSelectedValueSet('1');
</script>
Script Block :
function RadionButtonSelectedValueSet(SelectdValue) {
$('#RBLExperienceApplicable').val(SelectdValue);
//$("input[name='RBLExperienceApplicable']:checked").val(SelectdValue);
}
Try
function RadionButtonSelectedValueSet(name, SelectdValue) {
$('input[name="' + name+ '"][value="' + SelectdValue + '"]').prop('checked', true);
}
also call the method on dom ready
<script type="text/javascript">
jQuery(function(){
RadionButtonSelectedValueSet('RBLExperienceApplicable', '1');
})
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments