Situation:
I'm using javascript to put together a user profile form and am in need of a little help with regard to checkbox inputs. The goal is to have a form that returns all input information to a mysql database (such as name, job, etc etc), then for the form to also be updated by the user, once saved.
I've been able to get the database query to work with the text inputs so that users can see data they've previously saved. I do however have one spot where I need a checkbox input for each user for a simple binary answer. I figured I'd store the information such that checked=1 unchecked=0.
Problem:
While I can get the checked info to save just fine as value=1, I'm looking for a way to make the box check display the check once the person has saved the answer and has come back to edit it. Also, I'm looking for a way to also allow that user to uncheck the box and overwrite value=1 with value=0.
I figure I could use some sort of sloppy if-statement fiasco to accomplish this, but I was just wondering what best practices are generally used in this situation. (If you can't tell I'm slowly learning my way through web development)
My checkbox is displayed like so:
<tr><td id='ownershipquestion' colspan='2'>Does this person have an ownership stake?</td><td id='ownershipbox'><input type='checkbox' id='part_owner' name='owner' value='1'/>Yes</td></tr>\
Previously saved values are obtained like so:
owner: $("#dialog input[name=owner]").attr("value"),
And updated value is returned like so:
item.find("input[name=owner]").attr("value",p.owner);
Any suggestions would be appreciated; thanks in advance!