I have two files test.html and test2.html I am able to save the value of the forms but cannot fill the input field in test2.html form.
Test.html
<script type="text/javascript">
function store(){
var inputEmail= document.getElementById("email");
localStorage.setItem("email", inputEmail.value);
}
</script>
<form action="test2.html" class="form-login" method="post" />
<input name="email" type="email" id="email" required="" placeholder="Email" />
<button onclick="store()" type="button">StoreEmail</button>
Test2.html
<script type="text/javascript">
function get(){
var storedValue = localStorage.getItem("email");
document.getElementById("email").innerHTML = storedValue;
document.getElementById("email").value = storedValue;
}
</script>
<p id="email">qqqqqq</p>
<form action="" class="form-login" method="post" />
<input name="email" type="email" id="email" placeholder="Email" />
<button onclick="get()" type="button">getEmail</button>
When I click on getEmail button the paragraph changes but the Email input field doesn't change with the value. Please help.
The id of every DOM node is supposed to be unique within the entire DOM
document.getElementById returns always the first matched dom node
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.