Note that there are some explanatory texts on larger screens.

plurals
  1. POCookie returns undefined value in JavaScript
    text
    copied!<p>I want to make a cookie to remember a radius that a user can choose. The problem is that the cookie works, but the value of the cookie is undefined. I don't know what I am doing wrong.</p> <p>The function "opslaan" is linked with a button on the HTML page.</p> <pre><code>function opslaan() { createCookie('radius',document.getElementById("range").value,8); alert("opgeslagen"); } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0; i &lt; ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); var expires = ";expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires +";path=/"; } </code></pre> <p>This is the button and the range field where it need to get the value out:</p> <pre><code>&lt;fieldset class="one-third column"&gt; &lt;label for=""&gt;Radius van de kaart (km)&lt;/label&gt; &lt;input type="range" min="5" max="20" value="5" step="5" onchange="showValue(this.value)" /&gt; &lt;span id="range"&gt;5&lt;/span&gt; &lt;script type="text/javascript"&gt; function showValue(newValue) { document.getElementById("range").innerHTML=newValue; } &lt;/script&gt; &lt;/fieldset&gt; &lt;script&gt; alert(readCookie('radius')); &lt;/script&gt; &lt;div class="one-third column"&gt; &lt;a class="full-width button margin-top25" href="home.html" onclick="opslaan()"&gt; Opslaan &lt;/a&gt; &lt;/div&gt; </code></pre> <p>It seems to be working without the range field and button.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload