jquery - tips on using checkbox inputs in editable javascript form -


situation:

i'm using javascript put user profile form , in need of little regard checkbox inputs. goal have form returns input information mysql database (such name, job, etc etc), form updated user, once saved.

i've been able database query work text inputs users can see data they've saved. have 1 spot need checkbox input each user simple binary answer. figured i'd store information such checked=1 unchecked=0.

problem:

while can checked info save fine value=1, i'm looking way make box check display check once person has saved answer , has come edit it. also, i'm looking way allow user uncheck box , overwrite value=1 value=0.

i figure use sort of sloppy if-statement fiasco accomplish this, wondering best practices used in situation. (if can't tell i'm learning way through web development)

my checkbox displayed so:

<tr><td id='ownershipquestion' colspan='2'>does person have ownership stake?</td><td id='ownershipbox'><input type='checkbox' id='part_owner' name='owner' value='1'/>yes</td></tr>\ 

previously saved values obtained so:

owner: $("#dialog input[name=owner]").attr("value"), 

and updated value returned so:

item.find("input[name=owner]").attr("value",p.owner); 

any suggestions appreciated; in advance!

with jquery, can read checked status (i.e. checked or not) via prop() method (read here).

this gives bool value. input of type checkbox has (text) value, you'd this:

owner: $('input[name=foobar]').prop("checked")     ? $('input[name=foobar]').val()     : '', 

later on, can set (from integer), so:

item.find("input[name=owner]").prop("checked", p.owner ? true: false);

mind html code above shows text input field..


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -