Reputation: 7
I am trying to transfer a variable from one page using this code:
<a href="login.html" onclick="NameFunction('asdf');">Edit</a>
to the page login.html
, and insert the variable(asdf
in this example) to a textbox
in the new page.
I have tried this code:
function NameFunction(name) {
document.getElementById("username").value = name;
}
It is not working. I think it doesn't work because thats another page.
Upvotes: 1
Views: 41
Reputation: 906
you can try using localStorage.
In you're onClick method, save the data you want to store in localStorage
localStorage.setItem(key,value);
When the new page loads, in the onLoad (ready function if using jquery) method get the data from localStorage and set it in the textbox
you can find more about localStorage in the following links
Storing Objects in HTML5 localStorage
http://www.w3schools.com/html/html5_webstorage.asp
and many more are available online
Upvotes: 0
Reputation: 1612
If you want to pass parameters to another page you can put them using query string:
<a href="login.html?param=asdf">Edit</a>
To get parameter on the login.html
page you can use jQuery as it described here: Get escaped URL parameter
Upvotes: 1