Note that there are some explanatory texts on larger screens.

plurals
  1. POPhoneGap javascript localStorage Android
    text
    copied!<p>So I'm trying to test this in a PhoneGap application using this method: <a href="http://inflagrantedelicto.memoryspiral.com/2013/05/phonegap-saving-arrays-in-local-storage/" rel="nofollow">http://inflagrantedelicto.memoryspiral.com/2013/05/phonegap-saving-arrays-in-local-storage/</a></p> <p>I keep getting a reference error when the code gets to the: <em>window.localStorage.setItem</em> and <em>window.localStorage.setArray</em></p> <p>JS:</p> <pre><code>Storage.prototype.setArray = function (key,obj) { return this.setItem(key, JSON.stringify(obj)); } Storage.prototype.getArray = function (key) { return JSON.parse(this.getItem(key)); } var storedSettings = window.localStorage.getArray('mysettings'); alert('storedSettings = ' + storedSettings); if (storedSettings === null) { var settings = newArray(); } else { var settings = storedSettings; } $(document).ready(function() { $('input[type=submit]').click(function() { alert('sup'); var xsize = $('input[name=rads]:checked').attr('id'); var xfirstname = $('#fname').val(); var xsex = $('input[name=mf]:checked').attr('id'); settings.push({'size':xsize, 'fname':xfirstname, 'sex':xsex}); window.localStorage.setItem('mysettings', settings); window.localStorage.setArray('mysettings', settings); alert('settings:\n#1: ' + settings[0] + '\n#2: ' + settings[1] + '\n#3: ' + settings[2]); }); }); </code></pre> <p>HTML:</p> <pre><code>&lt;label for='small'&gt;small&lt;/label&gt; &lt;input type='radio' name='rads' id='small' checked='checked'/&gt;&lt;br/&gt; &lt;label for='medium'&gt;medium&lt;/label&gt; &lt;input type='radio' name='rads' id='medium'/&gt;&lt;br/&gt; &lt;label for='large'&gt;large&lt;/label&gt; &lt;input type='radio' name='rads' id='large'/&gt; &lt;br/&gt; &lt;br/&gt; &lt;input type='text' id='fname' size='10'/&gt; &lt;br/&gt; &lt;label for='male'&gt;M:&lt;/label&gt; &lt;input type='checkbox' id='male' name='mf' checked='checked'/&gt; &lt;br/&gt; &lt;label for='female'&gt;F:&lt;/label&gt; &lt;input type='checkbox' id='female' name='mf'/&gt; &lt;br/&gt; &lt;br/&gt; &lt;input type='submit' onclick='goset();' value='Save Settings'/&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload