How Do I Make An Html Radio Button Display As Selected At Launch Time When The Stored Value="on"?
Using Javascript and html: I have a list containing radio buttons that is dynamically loaded at launch time based on stored data. Even though the stored value of the radio is 'on'
Solution 1:
Using JQuery you should be able to check any radio button like this.
$(".dfsales").attr("checked", true);
EDIT:
This does seem to work:
$(document).ready(function(){
var dfsales = 1;
$('<input type="radio" name="colorInput" id="test" value="2">').appendTo($("#list"));
if(dfsales !== undefined){
$('#test').attr('checked', true);
}
})
EDIT 2: Eric, assuming you only care to set the value of the radio button if dfsales == on this will work.
if (defsales !== undefined && defsales == 'on') {
$('.defsales', newRow).val(defsales).attr('checked', true);
}
if you want the radio button value to be set regardless, then try something like this:
if (defsales !== undefined){
$('.defsales', newRow).val(defsales);
if(defsales == 'on'){
$('.defsales', newRow).attr('checked', true);
}
}
Does this help?
Solution 2:
I'm not entirely sure what it is you're doing outside of this problem or more importantly why you're doing it... but I think this may solve/help with your problem (untested).
if (defsales !== undefined) {
$('.defsales').each(function() {
$(this, newRow).val(defsales);
if($(this).val() == 'on') {
$(this).attr('checked', 'checked');
}
});
}
Post a Comment for "How Do I Make An Html Radio Button Display As Selected At Launch Time When The Stored Value="on"?"