<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script type="text/javascript"> var tab = new Array(); function add() { tab.push(document.getElementById('valuetoins').value); EcrireCookie(); aff_tab(); //alert(tab); } function aff_tab() { var rendu=document.getElementById('aff_tableau'); //suppression des éléments de la div while (rendu.hasChildNodes()) { rendu.removeChild(rendu.firstChild); } //on remplit la div avec les éléments du tableau for(i=0;i<tab.length;i++) { var noeudtexte = document.createTextNode(tab[i]); var saut = document.createElement('br'); rendu.appendChild(noeudtexte); rendu.appendChild(saut); } } function EcrireCookie() { // var tableau_plat = tab.join('%2C'); document.cookie="tableau="+escape(tab); } function LireCookie() { if(document.cookie) { var a_recherche = "tableau="; var valeurdepart = document.cookie.indexOf(a_recherche) + a_recherche.length; var valeurfin = document.cookie.indexOf(";"); if(valeurfin == -1) valeurfin = document.cookie.length; var tableau_plat=document.cookie.substring(valeurdepart,valeurfin); tab = tableau_plat.split('%2C'); } return true; } </script> </head> <script type="text/javascript"> LireCookie(); aff_tab(); </script> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script type="text/javascript"> var tab = new Array(); function add() { tab.push(document.getElementById('valuetoins').value); EcrireCookie(); aff_tab(); //alert(tab); } //Suppression de l'indice passé en param function supp(indice) { var tab_tmp = new Array(); for (i=0;i<tab.length;i++) { if (i!=indice) { tab_tmp.push(tab[i]); } } tab = tab_tmp; EcrireCookie(); aff_tab(); } function aff_tab() { var rendu=document.getElementById('aff_tableau'); //suppression des éléments de la div while (rendu.hasChildNodes()) { rendu.removeChild(rendu.firstChild); } //on remplit la div avec les éléments du tableau for(i=0;i<tab.length;i++) { var noeudtexte = document.createTextNode(tab[i]); var ancre = document.createElement('a'); var saut = document.createElement('br'); ancre.href='#'; ancre.id=i; ancre.onclick = function () { supp(this.id) ; return true ; } ; ancre.appendChild(document.createTextNode('X')); rendu.appendChild(noeudtexte); rendu.appendChild(ancre); rendu.appendChild(saut); } } function EcrireCookie() { // var tableau_plat = tab.join('%2C'); document.cookie="tableau="+escape(tab); } function LireCookie() { if(document.cookie) { var a_recherche = "tableau="; var valeurdepart = document.cookie.indexOf(a_recherche) + a_recherche.length; var valeurfin = document.cookie.indexOf(";"); if(valeurfin == -1) valeurfin = document.cookie.length; var tableau_plat=document.cookie.substring(valeurdepart,valeurfin); tab = tableau_plat.split('%2C'); } return true; } </script> </head> <script type="text/javascript"> LireCookie(); aff_tab(); </script> </html>
var tab = new Array("hello", "holla"); function add() { tab.push(document.getElementById('valuetoins').value); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<script type="text/javascript"> var tab = new Array("hello", "holla"); function add() { tab.push(document.getElementById('valuetoins').value); alert(tab); } </script>
[test_cookie.html On affiche le cookie ailleurs]
<SCRIPT language="JavaScript" src="url.js"></SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Cookie</title> <script type="text/javascript"> var tab = new Array(); function add() { tab.push(document.getElementById('valuetoins').value); EcrireCookie(); aff_tab(); //alert(tab); } function supp(indice) { var tab_tmp = new Array(); for (i=0;i<tab.length;i++) { if (i!=indice) { tab_tmp.push(tab[i]); } } tab = tab_tmp; EcrireCookie(); aff_tab(); } function aff_tab() { var rendu=document.getElementById('aff_tableau'); //suppression des éléments de la div while (rendu.hasChildNodes()) { rendu.removeChild(rendu.firstChild); } //on remplit la div avec les éléments du tableau for(i=0;i<tab.length;i++) { var noeudtexte = document.createTextNode(tab[i]); var ancre = document.createElement('a'); var saut = document.createElement('br'); ancre.href='#'; ancre.id=i; ancre.onclick = function () { supp(this.id) ; return true ; } ; ancre.appendChild(document.createTextNode('X')); rendu.appendChild(noeudtexte); rendu.appendChild(ancre); rendu.appendChild(saut); } } function EcrireCookie() { // var tableau_plat = tab.join('%2C'); document.cookie="tableau="+escape(tab); } function LireCookie() { if(document.cookie) { var a_recherche = "tableau="; var valeurdepart = document.cookie.indexOf(a_recherche) + a_recherche.length; var valeurfin = document.cookie.indexOf(";"); if(valeurfin == -1) valeurfin = document.cookie.length; var tableau_plat=document.cookie.substring(valeurdepart,valeurfin); tab = tableau_plat.split('%2C'); } return true; } </script> </head> <script type="text/javascript"> LireCookie(); aff_tab(); </script> </html>