Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to save user text input html input as cookie
    text
    copied!<p>I have a lot of trouble writing HTML that is intermingled with JavaScript. I have a input box that assigns the input to a variable. I want that input box to assign the input to the cookie and if there is a cookie entered in the site it redirects you. Now I have I am able to have it redirect you if you have the cookie entered, at least i think and also I have an input box. Now If anyone could help me with this that will be great. </p> <p>Here is the code for the cookie</p> <pre><code>function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i&lt;ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } function checkCookie() { var user=getCookie("username"); if (user!="") { window.location.assign("http://....") //if the user has a cookie saved it will redirect them to a newpage } else { user = prompt("Please enter your name:",""); // I do not want a prompt I want a input box if (user!="" &amp;&amp; user!=null) { setCookie("username",user,30); } } } &lt;/script&gt; </code></pre> <p>Here is the html for the input box:</p> <pre><code>&lt;div id="container"&gt; &lt;input type="text" id="input"/&gt; &lt;button id="trigger"&gt;enter&lt;/button&gt; &lt;/div&gt; </code></pre> <p>Here is the javascript that make the input a variable:</p> <pre><code> var trigger = document.getElementById("trigger"); trigger.addEventListener("click", function () { var input = document.getElementById("input"); }, false) </code></pre> <p>You don't have to use my html but to recap: I would like an input box not a pop up where users but some info for their cookie and if the info is in there it redirects them to another page. </p> <p>How do make a string a cookie? Or how do you make an input the cookie?</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