2017-03-24 17 views
0

1つのhtmlページから別のhtmlページにテキストボックス値を渡して2ページ目に印刷したいと思います。私はpage1.htmlとpage2.htmlを持っています。私はASPやPHPのスクリプト言語を使用したいとは思っていません。簡単にjavascriptやjqueryを使ってやりたいと思っています。1つのhtmlページから別のhtmlページにテキストボックス値を渡す方法

<script> 
 
     function checkPassword() { 
 
      if (document.getElementById("name").value == "") { 
 
       document.getElementById("studname").innerHTML = "Enter your name. Field cannot be left blank."; 
 
       alert('Enter your name.'); 
 
       return false; 
 
      } 
 
      else if (document.getElementById("class").value == "select") { 
 
       document.getElementById("classname").innerHTML = "Select your class."; 
 
       alert('Select your class.'); 
 
       return false; 
 
      } 
 
      else if (document.getElementById("section").value == "select") { 
 
       document.getElementById("secname").innerHTML = "Select your section."; 
 
       alert('Select your section.'); 
 
       return false; 
 
      } 
 
      else if (document.getElementById("password").value == "") { 
 
       document.getElementById("passwordname").innerHTML = "Enter your password."; 
 
       alert('Enter your password.'); 
 
       return false; 
 
      } 
 
      else if (document.getElementById('password').value == '12345' && document.getElementById("class").value == 'V' && document.getElementById("section").value == 'a') { 
 
       location.href = 'Start.html?name=' + document.getElementById('name').value + '?class=' + document.getElementById('class').value; 
 
      } 
 
      else { 
 
       alert('Your Class, Section and Password doesn\'t match. Please re-enter correctly.'); 
 
       return false; 
 
      } 
 
     } 
 
     </script>

+0

クエリ文字列、のlocalStorage。 ? –

答えて

0

実行このコードは、uがuは必要なものを出力を得るでしょう。

html1.html

<html> 
<form type=get action="html2.html"> 
<table> 
<tr> 
<td>First Name:</td> 
<td><input type=text name=firstname size=10></td> 
</tr> 
<tr> 
<td>Last Name:</td> 
<td><input type=text name=lastname size=10></td> 
</tr> 
<tr> 
<td>Age:</td> 
<td><input type=text name=age size=10></td> 
</tr> 
<tr> 
<td colspan=2><input type=submit value="Submit"> 
</td> 
</tr> 
</table> 
</form> 
</html> 

html2.html

<html> 
<script LANGUAGE="JavaScript"> 
function getParams(){ 
var idx = document.URL.indexOf('?'); 
var params = new Array(); 
if (idx != -1) { 
var pairs = document.URL.substring(idx+1, document.URL.length).split('&'); 
for (var i=0; i<pairs.length; i++){ 
nameVal = pairs[i].split('='); 
params[nameVal[0]] = nameVal[1]; 
} 
} 
return params; 
} 
params = getParams(); 
firstname = unescape(params["firstname"]); 
lastname = unescape(params["lastname"]); 
age = unescape(params["age"]); 
document.write("firstname = " + firstname + "<br>"); 
document.write("lastname = " + lastname + "<br>"); 
document.write("age = " + age + "<br>"); 
</script> 
</html> 
関連する問題