Hi guys,
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" the radio at launch does not display as selected.
I cant figure out what I'm missing.
if (defsales !== undefined) {
$('.defsales', newRow).val(defsales); }
defsales being the class identifier of the radio.
Do I need an additional argument to check the value? Or, do I need to add something that reapplies the value after launch?
I've been working at this problem long enough that I'm getting confused.
Please excuse my ignorance,
If it helps, here is the rest of the function:
function addSalespersonRow(id, name, phone, email, defsales) {
var newRow = $('<tr>'+
'<td><input type="hidden" class="id" /><input class="name" size="20" /></td>'+
'<td><input class="phone" size="15"/></td>'+
'<td><input class="email" size="30"/></td>'+
'<td><input type="radio" name="salespersons" class="defsales" /></td>'+
'<td><a href="#" onclick="$(this).parent().parent().remove(); return false;">Delete</a></td>'+
'</tr>');
if (id === undefined) {
id = new Date().getTime();
}
$('.id', newRow).val(id);
if (name !== undefined) {
$('.name', newRow).val(name);
}
if (phone !== undefined) {
$('.phone', newRow).val(phone);
}
if (email !== undefined) {
$('.email', newRow).val(email);
}
if (defsales !== undefined) {
$('.defsales', newRow).val(defsales);
}
$('#salespersons-table tbody').append(newRow);
return false;
}
Here was the code that worked correctly.
if (defsales !== undefined && defsales == "on") {
$('.defsales', newRow).attr('checked', true);
}
Thanks to Matt, for pointing me in the right direction.