javascript - Display the results of an array on another page -
i'm trying load array 1 page , have results appear on using javascript/jquery. user make selection dropdown. based on dropdown "customers" address, phone, email, etc. appear in text field. i'm trying store results in array (name | address | etc in 1 index of array), display result on second screen, , allow user add more names if necessary.
at moment i'm trying use localstorage store values , json.stringify convert results can stored in array.
i think these of pertinent lines:
var customerarray = []; var getname = $('#dropdownlist1').val(); var getaddress = $('#datalist1').text().trim(); var getphone = $('#datalist2').text().trim(); var getemail = $('#datalist3').text().trim(); //store variables localstorage.setitem("name", getname); localstorage.setitem("address", getaddress); localstorage.setitem("phone", getphone); localstorage.setitem("email", getemail); //user click #btnadd add customers information //into customerarray[] $("#btnadd").click(function () { var setname = localstorage.getitem("name"); var setaddress = localstorage.getitem("address"); var setphone = localstorage.getitem("phone"); var setemail = localstorage.getitem("email"); var post = setname + setaddress + setphone + setemail; if (customerarray.length == 0) { customerarray[0] = post; } else { (var = 1; < customerarray.length; ++i) { //store results of 'post' array customerarray.push(post); localstorage.setitem("storedarray",json.stringify(customerarray)); } } }); //end #btnadd click event
form here 2nd page load text field (should) display results of array (customerarray). unfortunately can 1 value appear.
at moment block being used display results:
$('#tbcontactlist').val(json.parse(localstorage.getitem("storedarray")));
if matters i'm writing application using visual studio express 2012 web. data populates customers information comes database i've used asp controls get. i'm confident there simple solution using asp/c# i'm trying solve problem using javascript/jquery - i'm more familiar languages c#.
thank you.
use array.join() turn array string store. use array.split() turn string array.
example
var arr=['name','email','other']; var localstoragestring=arr.join(','); localstorage.setitem('info',localstoragestring); var reassemble=localstorage.info.split(','); for(var i=0;i<reassemble.length;i++){ document.body.innerhtml+=reassemble[i]+"<br/>"; }
why user have leave current page though? tabbed/dynamic interface not option?
Comments
Post a Comment