1

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.

1 Answer 1

3

The id of every DOM node is supposed to be unique within the entire DOM

document.getElementById returns always the first matched dom node

Sign up to request clarification or add additional context in comments.

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.