0

I don't know if this type of question would have been asked before but i don't care because some of their answers haven't been clear enough in my opinion. I have created a sample page which will take in a random input and store it as a cookie, which works fine. But what i want to achieve is that par example if the page was reloaded or you closed and re-opened the browser and you clicked on the textbox, the input you entered before will be available to you to use again.

Here is my Code:

<html>
<head>
    <script type="text/javascript">
        function cookie_Saver()
        {
            var cookieV = document.forms["sampleform"]["samplebox"].value;
            var theDate = new Date(2014, 07, 09);
            theDate = theDate.toUTCString();
            document.cookie = "text="+cookieV+";expires="+theDate;
            alert("Done");
        }
    </script>
</head>

<body>
    <form name="sampleform">
        Enter Cookie Text<input type="text" name="samplebox" id="samplecookiebox">
        <button type="button" onclick="cookie_Saver()">Submit</button>
    </form>
</body>

I want to be able to do this with html and javascript only your input would be really appreciated

Kebab Programmer
  • 1,213
  • 2
  • 21
  • 36
  • Using cookies for this is *soooo* last millennium. Try `localStorage` instead ;) – Niet the Dark Absol Jul 08 '14 at 16:46
  • Banana, as i said, i already checked other questions, and they were not clear enough, thats why i asked this question already – Kebab Programmer Jul 08 '14 at 16:52
  • You could at least say *what* wasn't clear if you insist on having a new question. Something like: "*I'm trying to do X, I found Q1 & Q2 that were similar, but point Y wasn't clear. What does Y mean?*"... – Bruno Jul 08 '14 at 23:11

1 Answers1

0

Just use the getCookie function from Read cookies with JavaScript

    function cookie_loader()
    {
        document.forms["sampleform"]["samplebox"].value = getCookie("text");

    }

Put this call this function onLoad.

Community
  • 1
  • 1
Mochan
  • 84
  • 1
  • 5