将输入详细信息从一个页面传递到另一个页面textarea

时间:2017-12-29 15:37:55

标签: javascript html

我自己是初学者,处于学习阶段。我想将输入详细信息从一个页面(test1.html)传递到下一页textarea(test2.html)。附上两个html文件。

test1.html(第一页)



<html>

<body>

      <form method="post"  action="test2.html">
      <label><b>Customer Name</b></label>
      <input type="text" placeholder="Enter Customer Name" name="cname" id="cname"  required>


   <script>
      function ()  {
        localStorage.setItem('mySharedData1', document.getElementById('cname').value);

}
</script>  
      <button type="submit" name='submit' id='submit'>Submit</button>

      <input type="checkbox" checked="checked"> Remember me


</body>
</html>
&#13;
&#13;
&#13;

test2.html(第二页)

&#13;
&#13;
<html>

<body>
<form method="get"  action="test1.html">
<fieldset class="fieldset-auto-width">
  <legend><b><font color="#0000FF">Your Bookings Are..!</font color></b></legend>
  <textarea cols="35" rows="19" id="Requirement1" ></textarea>

<script type="text/javascript">
var mySharedData = localStorage.getItem('mySharedData1');
 function(){
	Requirement1.value =Requirement1.value+document.getElementById('mySharedData1').innerHTML+this.value+",                                      "; 
}

</script>    
</fieldset>
</form>
 
</body>
</html>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

您必须在两个html页面中为该函数命名,并实际使用onclick attribute提交的button。我只在一页上写过

<html>

<body>

      <form method="post"  action="test2.html">
      <label><b>Customer Name</b></label>
      <input type="text" placeholder="Enter Customer Name" name="cname" id="cname"  required>


   <script>
      function giveMeOneName()  {
        localStorage.setItem('mySharedData1', document.getElementById('cname').value);

}
</script>  
      <button type="submit" name='submit' id='submit' onclick="giveMeOneName()">
      Submit
    </button>

      <input type="checkbox" checked="checked"> Remember me


</body>
</html>

答案 1 :(得分:0)

 function(){
    Requirement1.value =Requirement1.value+document.getElementById('mySharedData1').innerHTML+this.value+",                                      "; 
}

这应该是:

function getValue() {
  var value = localStorage.getItem('mySharedData1');
  document.getElementById('Requirement1').innerHTML = value;
}

答案 2 :(得分:0)

您需要创建一个函数并在单击提交时调用该函数。

<form>
    <label>
        <b>Customer Name</b>
    </label>
    <input type="text" placeholder="Enter Customer Name" name="cname" id="cname" required>


    <script>

        function setValue() {
            localStorage.setItem('mySharedData1', document.getElementById('cname').value);

        }
    </script>
    <button type="submit" name='submit' id='submit' onClick="setValue()">Submit</button>

    <input type="checkbox" checked="checked"> Remember me