stevenhu — 2011-08-22T16:04:57-04:00 — #1
<li><input placeholder="note:" maxlength="30" type="text" name="s1frontSuspensionnotes" id="s1frontSuspensionnotes" /></li>
But if I use a series of checkboxes, then the checkbox data is not saved (note in the following that the "name" for all check boxes is the same to keep them in the group, while the "id" distinguishes each option selected):
<span class="topcheckbox"><input type="checkbox" name="s1frontTowerMtgShock" id="s1frontTowerMtgShock3" value="3-outer" /></span>
<br><span class="nextcheckboxes"><input type="checkbox" name="s1frontTowerMtgShock" id="s1frontTowerMtgShock2" value="2-middle" /></span>
<br><span class="nextcheckboxes"><input type="checkbox" name="s1frontTowerMtgShock" id="s1frontTowerMtgShock1" value="1-inner" /></span>
Can anyone tell me why text fields save in the localstorage, but the checkboxes don't? I've also tried making the name= group name the same as the checkbox id, line for line, and updated the localstorage code to reflect the change, but it did not work. The text fields do save, so I know the local storage stuff works.
I put this in the HTML section because localstorage is part of HTML5, and checkboxes and text fields are part of HTML.
stevenhu — 2011-08-24T15:58:17-04:00 — #2
Is my question hard to understand? How can I make it clearer?
stevie_d — 2011-08-24T16:25:10-04:00 — #3
Sorry, but I don't know what you mean by 'localstorage'
You do need to give checkboxes unique names, so that each input name gets one answer (in this case, on/off).
The only time you can use one name for multiple inputs is when you're giving options with radio buttons, where only one of the options can be selected at a time so there is only one answer to the input.
stevenhu — 2011-08-25T14:08:39-04:00 — #4
I think you hit on the answer! I was treating them as <option>s or radio buttons! I'll try this out and get back to you.
stevenhu — 2011-08-25T15:48:32-04:00 — #5
Here is an article on html5 and local storage:
My checkbox problem is still not solved, even with after changing to unique names.
brense — 2011-08-26T03:18:42-04:00 — #6
why did you assign values to your checkboxes?
and wouldnt it be easier to use a select menu with options? then you can assign values.
stevenhu — 2011-09-27T13:33:08-04:00 — #7
It included values in case later I wanted to output the information as key/value pairs.
kansel — 2011-09-28T14:47:39-04:00 — #8
BTW, using checkboxes in a group (all with the same name attribute) is completely valid. When selecting multiple checkboxes in the same group only those that are checked will send their values to the server (assuming a normal form submit). When dealing with many options, a checkbox group is way easier to deal with (usability wise at least) than a multiple-select box.
foresterh — 2011-10-06T12:11:43-04:00 — #9
My guess is that you are not storing the data in localStorage correctly. The easiest way to do this (without seeing your code) is to convert it to and from a string when saving and retrieving.
For example (haven't tried running it... make sure punctuation is correct):