2017-12-29 6 views
-1

私は初心者で学習段階です。入力の詳細をあるページ(test1.html)から次のページのテキストエリア(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>

test2.html(2ページ目)

<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(){ 
 
\t Requirement1.value =Requirement1.value+document.getElementById('mySharedData1').innerHTML+this.value+",          "; 
 
} 
 

 
</script>  
 
</fieldset> 
 
</form> 
 
    
 
</body> 
 
</html>

+1

問題があるか、どのように行うのか分かりませんか? – CherryPlaysRoblox

+0

テキストが第2ページのテキスト領域に表示されません。私はどのように私は "getvalue()"関数を呼び出すことができます –

答えて

0

に両方のhtmlページの機能を使用し、実際にbutton Submitのonclick attributeを使用してください。私はこれがあるべき1ページのみ

<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>

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

に書いた:

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

を取得しようとしている? –

0

は、Submitをクリックする上で、その関数を関数を作成して起動する必要があります。

<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 

+0

そのセットがlocalStorageにあるかどうかをチェックする。入力することができますlocalStorage.mySharedData1 –

+0

応答ありがとう。残念ながら私はまだ結果を得ていません。 plsはlocalStorage.mySharedData1と入力する場所を教えてくれますか? –

+0

コンソールウィンドウ。コンソールウィンドウを開くには、f12キーを押すか、場合によってはCtrl + Alt + Iキーを押します。その後、コンソールウィンドウにlocalStorageと入力すると、サイトに保存されているすべてのローカル状態が表示されます。 localStorage.mySharedData1と入力すると、そのオブジェクトで使用可能なすべての状態が表示されます。 –

関連する問題