I have tried to get this to work but haven't been successful. I am a a real nube with js so please keep that in mind when trying to help me. You'll have to spell it out for me cuz I just don't understand what is happening yet with all this code.
I have two things that I am trying to get working. One is a set of radio buttons. These buttons are a group meaning that only one radio button can be checked. The values that I have for these radio buttons are either 1 or 0 and are coming out of a database.
Here is the problem I am having. I can switch the buttons and change the vals in the db but when json calls the data out of the database, there is no change in the buttons to the user. For example: if I changed button A to true, or checked, the val in the db changes to 1. When that page is viewed from that moment on, button A should reflect that. Also, when the user checks B, the db val is then changed to 0 and the button should reflect that as well.
What I don't understand is how to switch the actual buttons to reflect the values in the database. Here is my code so far:
else if (item.field == "status" && item.value == "1"){
$("radio#status").attr("checked", "checked");
}
<input type="radio" id="active" name="status" value="1" checked="checked" class="chkbx">
<input type="radio" id="inactive" name="status" value="0" class="chkbx">
Here is my second issue. The checkboxes are exactly the same as the radio buttons with the exception that they are NOT a group. Each checkbox has its own value. Again I am using 0 and 1 but multiple checkboxes can be checked at one time. Here is the code for that as well.
else if (item.field == "rptDly" && item.value == "1"){
$("checkbox#rptDly").attr("checked", "checked");
}
<input type="checkbox" id="rptDly" name="rptDly" value="1" checked="checked" class="chkbx">
<input type="checkbox" id="rptSum" name="rptSum" value="1" checked="checked" class="chkbx">
<input type="checkbox" id="rptDtl" name="rptDtl" value="1" checked="checked" class="chkbx">
Can someone please guide me? When I put an alert in the js code above, I do get the alert so I know I'm good there but because I don't know js, I'm not able to troubleshoot this any further.
Thanks!
EDIT:
I found the original post that I am duplicating. Here is the post http://stackoverflow.com/questions/558445/dynamically-fill-in-form-values-with-jquery