php - How to add items to javascript array that can be accessed on another page? -


i have problem. have created php website , every item there "request quote" button. on clicking button, want item name added array (which doing through javascript).subsequently, array added request form "message" field on contact.php. have used -

<script language="javascript"> // empty array var empty = [];  // array containing initial elements. var arrayitem= ['hello'];  alert(arrayitem[1]); function myfunction(item) { arrayitem.push(item); var items=''; (var = 0; < arrayitem.length; i++) { items=items+','+(arrayitem[i]);    alert(items);  }; document.getelementbyid("message").value=arrayitem[1]; } </script> 

on header.php page, include on every page. have 2 more pages- 1. computers.php- contains computers items , 2. softwares.png- contains softwares items.

now problem is, when add items 1 page, appended array , works fine, when navigate page, items added previous page removed array ..and cant see araay items in "message field of contactus.php.".please help

you try using browser's localstorage store data in between page visits.

try javascript in header.php:

localstorage.setitem("preference", "10"); 

and in contact page try this:

console.log(localstorage.getitem("preference")); 

you should see "10" in browser console.

here's more info localstorage: http://diveintohtml5.info/storage.html


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -