Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pre select selectbox and checkbox based on localStorage using jQuery
    primarykey
    data
    text
    <p>The problem is that when I close the browser and test it again it does show the value, but when I refresh the page it doesn't show to the user the values already chosen previously,but the localStorage have the data stored.</p> <pre><code>&lt;form id="suspendedProperties"&gt; &lt;label for="stationDropdown"&gt;Select Station:&lt;/label&gt; &lt;select name="stationDropdown" id="stationDropdown" onChange="storeLocalContent(this.id,this.value)" &gt; &lt;option value="50028000"&gt;Tanama River&lt;/option&gt; &lt;option value="50010500"&gt;Rio Guajataca, Lares&lt;/option&gt; &lt;option value="60008002"&gt;Example River2&lt;/option&gt; &lt;option value="60008003"&gt;Example River3&lt;/option&gt; &lt;option value="60008004"&gt;Example River4&lt;/option&gt; &lt;/select&gt; &lt;label for="sampleMediumDropdown"&gt;Select Sample Medium:&lt;/label&gt; &lt;select name="sampleMediumDropdown" id="sampleMediumDropdown" onChange="storeLocalContent(this.id,this.value)"&gt; &lt;option value="WS"&gt;WS(Surface Water)&lt;/option&gt; &lt;option value="WSQ"&gt;WSQ(Surface Water QC)&lt;/option&gt; &lt;/select&gt; &lt;label for="date"&gt;Begin Date:&lt;/label&gt; &lt;input naem="date" id="beginDate" type="date" onChange="storeLocalContent(this.id,this.value)" /&gt; &lt;label for="hydroEvent"&gt;Hydrologic Event:&lt;/label&gt; &lt;select name="hydroEvent" id="hydroEvent" onChange="storeLocalContent(this.id,this.value)" &gt; &lt;option value="4"&gt;4- stable, low stage&lt;/option&gt; &lt;option value="5"&gt;5- falling stage&lt;/option&gt; &lt;option value="6"&gt;6- stable, high stage&lt;/option&gt; &lt;option value="7"&gt;7- peakstage&lt;/option&gt; &lt;option value="8"&gt;8- rising state&lt;/option&gt; &lt;option value="9" selected&gt;9- stable, normal stage&lt;/option&gt; &lt;option value="A"&gt;A- Not Determined&lt;/option&gt; &lt;option value="X"&gt;X- Not applicable&lt;/option&gt; &lt;/select&gt; &lt;label for="containerCuantity"&gt;Add: &lt;/label&gt;&lt;input type="number" min="1" value="1" id="containerCuantity"onChange="storeLocalContent(this.id,this.value)"/&gt; &lt;select id="singleMultiContainer"name="singleMultiContainer" onChange="storeLocalContent(this.id,this.value)"&gt; &lt;option value="single"&gt;Single container sample&lt;/option&gt; &lt;option value="multi"&gt;Multiple sets container&lt;/option&gt; &lt;/select&gt; &lt;h4 &gt;Analyses Requested:(Applies to all samples)&lt;/h4&gt; &lt;label for="analysesC"&gt;Concentration&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesC" value="C" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesSF"&gt;Sand-Fine break**&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesSF" value="SF"onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesSA"&gt;Sand Analysis**&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesSA"value="SA" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesT"&gt;Turbidity&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesT" value="T" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesLOI"&gt;Loss-on-ignition**&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesLOI" value="LOI" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesDS"&gt;Dissolved Solids&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesDS"value="DS" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesSC"&gt;Specific Conductance&lt;/label&gt; &lt;input type="checkbox" name="analysis" id="analysesSC" value="SC" onChange="isChecked(this.id,this.value)"/&gt; &lt;label for="analysesZ"&gt;Full-size fractions**&lt;/label&gt;&lt;input type="checkbox" name="analysis" id="analysesZ"value="Z" on onChange="isChecked(this.id,this.value)"/&gt; &lt;/form&gt; </code></pre> <p>This is my localStrg.js:</p> <pre><code>var ls = window.localStorage; function initialize(){ //Check if browser supports localStorage if(!Modernizr.localstorage){ alert("Your browser will not store data, please change or update your current browser"); return false; } if(ls.length!= 0){ for(i=0;i&lt;ls.length;i++){ getData(ls.key(i)); alert(ls.key(i)); } } } function storeData(id,value){ ls.setItem('#'+id,value); alert("Item saved"+' '+'#'+id); } function getData(id){ $(id).val(ls.getItem(id)); $(id).selectmenu('refresh'); } $(document).ready(function(e) { initialize(); }); </code></pre> <p>All I want to do is to show the user the values he have chosen previously in their respective fields. </p> <p>Example, if he chose option 4 in the dropdown and he refresh the page he should see option 4 already in the dropdown not option 1.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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