Francis Gabriel Rodriguez Francis Gabriel Rodriguez - 29 days ago 22
HTML Question

Document.write on a different html page

Hmm is it possible to

document.write
on other html page?

For example I create a two html page, the first page have a textfield and submit button. I enter a text in a textfield and after I click the submit button the value of the textfield will be transfer to the second html page and load the html page and write the value on it.

Just a beginner to javascript so bear with me please :D

Answer

Since you're using pure javascript and HTML, I assume server-side things are out of the picture. So Felix Kling's comment is actually, I think, a good way to go. Here's one way you could use localStorage to make this work:

/* index.html */
<form action="result.html" onsubmit="submit()">
  <input type="text" id="input">
  <input type="submit" value="Submit">
</form>
<script>
function submit() {
  var input = document.getElementById("input").value;
  localStorage.input = input;
}
</script>

/* result.html */
<div id="result"></div>
<script>
  document.getElementById("result").innerHTML = localStorage.input;
</script>