javascript - HTML - cookies between pages. -
I have a quiz in many HTML pages (I know that it can only be one, but this question (Q1: q1a, q1b, q1c, q1d; q2: q2a, q2b, q2c, q2d, etc.) with 4 radio buttons in each one, and I want to set a cookie with the name of the question (q1) in each page and the checked answer (for example q1a,) I have created this function to set a cookie:
function set_cookie (name, value) {var cookie_string = name = "=" + escape (value); Document.cookie = cookie_string; } And I have put it in every page of the quiz. It works well in every page, but when I use a function to use cookies in the last page, it gives this blank space. I have the function:
function get_cookie (cookie_name) {var results = document.cookie.match ('(| | | |)?' + Cookie_name + '= ([^;] * ) (| | $) '); If (results) return (unescape (result [2])); And tap return; } But when I call this function with the final level of the quiz function, it is empty:
function grade () {Var grade = 0; Var x = get_cookie ("q1"); Var y = get_cookie ("q2"); Warning (x); // to see that the function works fine ... var xx = 0; Var yy = 0; ... if (x == "q1a") xx = 20; // Right answer xx = 0; // Wrong answer if (y == "q2c") yy = 20; // right answer else yy = 0; // wrong answers ... ... grade = xx + yy; Warning ("Your Qualification" + Grade); } What am I doing wrong? If both pages are in the same directory, is it not possible to obtain cookies from one page on the second page? "post-text" itemprop = "text">
The best way to use local storage cookies will be to check 3 schools.
Obtaining this is really simple and can be taken to the whole page
I hope that helps!
Comments
Post a Comment