This is my first HTML page:
<!--first.html-->
<html>
<body>
<div data-role="page" data-theme="a" data-url="first" id="first">
<form id="form1" name="form2" action="checking.html">
<input type="text" name="txtFileName" id="txtFileName"/>
<!-- <button onClick="uploadFile();">Upload</button> -->
<input type="hidden" name="hidden1" value="">
<br><input type="submit" value="Send me your name!" onClick="submitform();"><br>
</form>
<script type="text/javascript">
function submitform()
{
document.forms.form1.hidden1.value=1;
alert("i am working");
document.form1.submit();
}
</script>
</div>
</body>
</html>
This is my second HTML page:
<!-- second.html -->
<html>
<head>
</head>
<body>
<h1>Javascript call after page loaded</h1>
<script>
function getQueryVariable2(variable) {
var query = window.location.search.substring(1);
document.write(query);
var vars = query.split("&");
document.write("<br />");
document.write(vars);
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
document.write("<br />txtFileName = " + getQueryVariable2("txtFileName"));
document.write("<br />hid1 = " + getQueryVariable2("hid1"));
</script>
hellllo
</body>
Here I want to display the contents of hidden1 from first.html. Please suggest to me what code I should use for this.
For sending data to two servelets make one button as a submit and the other as button. On first button send action in your form tag as normal, but on the other button call a JavaScript function here you have to submit a form with same field but to different servelets then write another form tag after first close.
in HTML5 you can use session to pass object from page to another:
1- create a sesison
sessionStorage.setItem('key', 'value');
2- read session:
sessionStorage.getItem('key')
check this example
Probably the best way in your case to use GET params like:
http://mysite//second.html?myparams=value
or if it's important or big data - use POST
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With