-1

im trying to send a data from one input to another page i use this code

page1.html

<html>
<body>

<form name="form1">
Value from page 2: <input type="text" 

name="page2value">
</form>

</body>
</html>

page2.html

<html>
<head>
<script type="text/javascript">

function sendToPageOne()
{
    var thisValue = document.getElementById('page2Value').value;
    window.location.form1.page2value.value = thisValue.href = "F:\page2.html";
}

</script>
</head>
<body>

<form name="form2">
<input name="page2Value" id="page2Value" type="text">   
</form>

<button onclick="sendToPageOne();">Send to page 1</button>
</body>
</html>
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • If you have a local path in your page then the page can be viewed only by someone on the same computer. If the page is being viewed across the network, the Javascript will run on the client computer, which won't know what `F:\page2.html` refers to. Are you sure this is what you need? – Jim Garrison Feb 09 '14 at 09:19

3 Answers3

1

Let me point out two mistakes

  1. window.location refers to the current page address. You cannot access form values via that.
  2. var thisValue = document.getElementById('page2Value').value; assigns thisValue with the value of the input. It does not have an href attribute.

If you want to send a value from one page to another you need to submit a form you should look into this link Transfer data from one HTML file to another

Community
  • 1
  • 1
anurupr
  • 2,294
  • 2
  • 20
  • 28
0

You should escape the backslash in "F:\page2.html". It should be:

"F:\\page2.html"

Note: Such code will not work once you deploy this somewhere as it is hard-referencing a local path.

techfoobar
  • 65,616
  • 14
  • 114
  • 135
0

when there are two pages opened and the pages are Not one other's parent or child, you cannot send data across them, but you can use cookies

scripter
  • 132
  • 8