score:0
Try this
var urarr = { 'date': 1, 'phn_num': 2};
// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(urarr));
// Retrieve the object from storage
var getObject = localStorage.getItem('urarr');
console.log('getObject: ', JSON.parse(getObject));
score:0
var texFieldName="abc"
var textFiledNumber="num"
var json={
"name":textFieldName,
"number":textFiledNumber
};
localStorage.setItem("data",json);
score:0
You should convert JSON to string and add event listener (with jQuery probably) on button click:
$('#button').click(function(e) {
var json = {};
json.tel = $('#tel').val();
json.name = $('#name').val();
localStorage.setItem('object', JSON.stringify(json));
});
// get Item
var jsonParse = JSON.parse(localStorage.getItem('object'));
score:0
$('#three').click(function () {
localStorage.data = JSON.stringify($('form').serializeArray());
console.log(localStorage.data);
});
<form>
<input type='text' name='one' id='one' />
<input type='text' name='two' id='two' />
<input type='submit' id='three' />
</form>
score:1
Try this,
// Call this function on button Click
function saveDataInLS(){
var obj={};
obj.name=document.getElementById('name').value;
obj.phone=document.getElementById('phone').value;
var listObj=localStorage.getItem('DATA');
if(listObj!=null){
listObj=JSON.parse(listObj); //this will give array of object
listObj.push(obj);
}else{
listObj=[obj]; //first time
}
// Save Data in Local Storage
localStorage.setItem('DATA',JSON.stringify(listObj));
//Please check Local Storage which will be like
//[{"name":"Anand","phone":"6546456456"}{"name":"Andy","phone":"78688"}]
}
To get Data From Local Storage use,
var dataArr= localStorage.getItem('DATA');
dataArr=JSON.parse(dataArr);//this Will return An JS Array
dataArr[0]['name']//to get Name for first index(i==0)
dataArr[0]['phone']//get contact number for first index(i==0)
Related Query
- How to encode php array in json and parse into jquery
- How to iterate through an HTML table column and input the values into a Javascript array using JQuery
- How to get values in Json Array and use each of them separately
- How to store javascript array or JSON into php
- How to insert an array into a hidden input in jquery
- how to structure a php array into json
- How to use jQuery in order to parse json and output it as a list into HTML?
- How to Add Text Inputs val() Into JSON Array
- How to put array of objects into new Json object
- How To Store localstorage Array Into MySQL Database?
- How use input type=file to upload json file
- How to use Ajax and JSON to get weather info and put it into an HTML paragraph?
- How to create a javascript array to send data into this json format?
- How to use twitter typeahead.js to select an option in a select control from a json array
- How can I use this localstorage example to plug into this script?
- How to render json in rails as an array of arrays without the metatags -- (passing data into google charts api javascript)
- How can I restrict the text entered into an input text element using jQuery?
- How to universally parse json into blocks using jquery?
- How to get the value of a select option, and use it to query an array, to populate another input
- How to pass the jquery variable into the input as a attribute
- How to use checkbox to checkall or uncheck all boxes into handsontable
- How do I a use Javascript or ajax to inject or add a the value of an input field in a textfield in real time?
- how to validate array input field using javascript
- How to form a JSON array using 1d array?
- Populate JSON file data into Array then feed Array into mmenu plugin
- Yii 2 ajax form submission how to get error to respective input as I received response in json
- How to pass an array id into jquery selector?
- how to use localstorage for login using javascript
- How to insert values to an array using input fields?
- how to use chosen but still allow input of text
- My Json array only returns the last array. How to fix that?
- How to use String.raw on array variables
- How can I use a function which is into another .js file?
- How to send and get JSON data from Node.js into HTML using Node.js
- how to force ajax to use browser cache to not load the updated json file
- How can I filter through json data by using the input checbox and showing or hiding products that meet the criteria
- How to access json array resides in function and loop with ng-repeat?
- JSON data push into Multi-Dimensional Array
- How to create json array in ajax jquery by loop and pass it in to rails controller
- How to append an element into a existing array in javascript/jquery
- How to put JSON content into <ul> tag and form in HTML
- How to handle Json data that is sometimes return in an array of objects and sometimes just an object?
- Convert a string of comma separated values into a JSON array
- How to return and use an array of strings from a jQuery ajax call?
- My app is sending me JSON. How do I take that JSON and inject HTML into the page?
- How can I convert an array of objects in JSON to an array with values only?
- how to use JSON Data in chart.js?
- How can I use javascript/jquery to prevent a decimal point from being typed into an HTML text field?
- How to access values in a multidimensional JSON array with jQuery
- How to Generate column heading and table values dynamically from JSON array in angularjs?
More Query from same tag
- bootstrap datepicker js disable future dates
- Can someone help me with using livestream's api to make a cross domain xml request?
- jQuery Ajax Render Fragments OR Whole Page
- Appending list toggle (jQuery Mobile) not rendering properly
- How to dynamically update highcharts using jQuery UI sliders
- Check what users are online
- Using setAttribute on a selected option
- Escalating height of list items
- How to convert not nested JSON into nested HTML list in Javascript (or Coffeescript)?
- Help me re-center a ModalPopup within an iframe when the iframe's parent window scrolls
- Onclick maximize div on other divs
- Is there any way in Yii2 to dynamically change URL without reloading? a part from pjax
- Responsive Chart.js Doughnut Chart with minimum height
- Hide or unhide text with button click
- JQuery checkbox filter parameter
- Issue with Chained Selects
- How can I enable google analytics tracking on Contact Form 7 when I have one or more checked checkbuttons?
- How to hide and show remove button on click button using jquery clone
- Show this element without having code repeating each time
- jquery on() method Maximum call stack size exceeded
- Post a huge html form by jQuery
- custom vertical image list view with ajax new image request
- Add HTML code in Javascript dropdown, Javascript dosen't evaluate HTML code
- How to remove the added append in tbody?
- How to use django view with jquery autosave?
- How can I check if the picture is fully loaded?
- How to add select2 with ajax to jquery query builder?
- How to format Ben Alman's jQuery Debounce
- How to stop the carousel slideshow from being too small in mobile view?
- The Buttons are not working in SignUp form