0

I want to save the username which is in text box to later retrieve it on another web page using javascript

<html>
<body>
<form method="post" action="index1.html">
username:<input type="text" name="uname" id="uname">
password:<input type="password" name="pass" id="pass">
login:<input type="submit" name="login" >
</form>
</body>
</html>

5 Answers 5

1
localStorage.setItem('username','myusername');

Now get the stored key

localStorage.getItem('username') //myusername
Sign up to request clarification or add additional context in comments.

2 Comments

i want the value of text box username in place of myusername
localStorage. setItem ('username',document.getElementById('uname').value)
0

it is possible using html5.We can store some values in localstorage in HTML5

see here

Comments

0

If your not using html5, You could store it in a cookie.

Comments

0

The context between page reloads is typically lost for JavaScript, you might want to consider using JQuery to provide an application that looks like it is running on multiple pages, but is in fact just one page with transitions.

Your other option is to store the value in a cookie, or in a local storage web database.

Comments

0

Yes it is possible. You have a button. Just call the method to store the values in the button click event.

  $(function () {

    $("#submit").click(function () {
        var name = $("#name").val();
        alert(name);
        localStorage.setItem('username',name);
    });
});

Fiddled Example here.

Local Storage API and a playground to try it yourself, HTML5.

The output, you will be able to see while you inspect element as a pair of Key and Value. Under resources tab, In case, you use firebug.

EDIT

I have also updated the sample fiddle.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.