I'm having a problem in my app where i will store the data in the localStorage everytime the client enter a case. here's my html using modal.
<div class="modal-body">
<div class="form-group">
<input class="form-control date-picker" placeholder="Month and Year" id="c_round" name="c_round">
</div>
<div class="form-group">
<select class="form-control" id="prov" name="prov">
<option>Select Province</option>
<option value="01">Province1</option>
<option value="02">Province2</option>
<option value="03">Province3</option>
</select>
</div>
<div class="form-group">
<select class="form-control" id="mun" name="mun">
<option>Select Municipality</option>
<option value="01">Municipality1</option>
<option value="02">Municipality2</option>
<option value="03">Municipality3</option>
</select>
</div>
<div class="form-group">
<select class="form-control" id="brgy" name="brgy">
<option>Select Barangay</option>
<option value="001">Barangay1</option>
<option value=:002>Barangay2</option>
<option value="003">Barangay3</option>
</select>
</div>
<div class="form-group">
<label for="commodity" class="control-label text-left">Household Classification</label>
<div class="form-horizontal">
<input type="radio" name="h_classification" value="Farming"> Farming   
<input type="radio" name="h_classification" value="Non-Farming"> Non-Farming
</div>
</div>
</div><!--End modal body-->
<div class="modal-footer">
<button type="submit" id="create" class="btn btn-primary pull-right" data-dismiss="modal" >Create</button>
</div>
When the client click the Create button the data will store in the localStorage here's my jquery.
$(function() {
var round = $("#c_round");
var prov = $("#prov");
var mun = $("#mun");
var brgy = $("#brgy");
var h_classification = $("[name='h_classification']");
var btn_create = $('#create');
var dataObject = [];
btn_create.on('click', function(){
if(typeof(Storage) !== "undefined"){
dataObj = [{
'user_id': user_id,
'prov' : prov.val(),
'mun' : mun.val(),
'brgy' : brgy.val(),
'r_code' : r_code,
'h_class': h_classification.val()
}];
dataObject.push(dataObj);
localStorage.setItem('dataObject', JSON.stringify(dataObject));
retrivedOjects = localStorage.getItem('dataObject');
console.log('retrivedOjects: ', JSON.parse(retrivedOjects));
}else {
alert("Error: Localstorage not supported");
}
});
});
When i refresh the page the old data is still there but when i create new data the old data is replaced by new data it doesn't append.
I want to stack many arrays in the localStorage("dataObjects") first before sending it on to the server for my offline mode application,
(sorry for my english)