How to transfer data from one html page to another [duplicate] - javascript

This question already has answers here:
How to Pass values form One html Page to Another html Page javascript?
(3 answers)
Closed 3 years ago.
I'm new to HTML and javascript. So basically I have 2 HTML files
a.html
<html>
<head>
<!-- Some Stuff-->
</head>
<body>
<script>
</script>
<!--In this part there is going to be a url of pdf.
I want that URL to be transferred to b.html
so that the same pdf could be shown.-->
</body>
</html>
b.html
<html>
<!-- Code goes here-->
</html>

<html>
<head>
<script language="javascript" type="text/javascript"
src="asd.js">
<body>
<form name="form1" action="next.html" method="get">
name:<input type ="text" id="name" name="n">
<input type="submit" value="next" >
<button type="button" id="print" onClick="testJS()"> Print </button>
</form>
</body>
</html>
<head>
<script language="javascript" type="text/javascript" src="asd.js">
</script>
</head>
<body>
function testJS()
{
var b = document.getElementById('name').value
document.getElementById('here').innerHTML = b;
}
<form name="form1" action="next.html" method="get">
<table>
<tr>
<td id="here">test</td>
</tr>
</table>
</form>

Related

how do i get a variable value from the <input type="number" > and use it in the script part? [duplicate]

This question already has answers here:
How to get a number value from an input field?
(4 answers)
Closed 5 months ago.
Here is my code
<html>
<head>
head
<title>title</title>
</head>
<script>
var val1 = parseInt(document.getElementById('input1'));
function bytton()
{
window.alert(val1);
}
</script>
<body>
<br>
<input type="number" id="input1"/>
<br>
<button type="button" onclick="bytton()">value of val1</button>
</body>
</html>
It runs properly without any problem.
At the input field i write a number in it and then click on the button but then it displays that the value is NaN,I think the value is not getting assigned to val1.
<html>
<head>
head
<title>title</title>
</head>
<script>
function bytton() {
window.alert(document.getElementById("input1").value);
}
</script>
<body>
<br>
<input type="number" id="input1"/>
<br>
<button type="button" onclick="bytton()">value of val1</button>
</body>
</html>

error in printing the variable in javascript

When I'm running this code it is not showing me the message which I want to display (i.e: res).Suppose I'm giving an input "$code$".Can anyone just help me out?
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<h1>Enter a sample message</h1>
<form>
<input type="text" name="a" id="a">
<button onclick="parse()">submit</button>
<p id="a"></p>
</form>
<script>
function parse(){
var msg=document.getElementById("a").innerHTML;
var res=msg.replace("$code$","1101");
document.getElementById("a").innerHTML=res;//this is to print res.
}
</script>
</body>
</html>
Two elements can't have the same ID. Further, an input element's value can not be obtained using the innerHTML property. Also, on clicking the submit button, the page will reload since the form get's submitted. To prevent that, call the function parse in an onsubmit on the <form> tag, and return false from the function.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<h1>Enter a sample message</h1>
<form onsubmit="return parse();">
<input type="text" name="a" id="a">
<button type="submit">submit</button>
<p id="b"></p>
</form>
<script>
function parse(){
var msg = document.getElementById("a").value;
document.getElementById("b").innerHTML = msg;
return false;
}
</script>
</body>
</html>
Check this:
<form>
<input type="text" name="a" class="input_field" id="a">
<button type="button" onclick="parse()">submit</button>
<p id="a"></p>
</form>
<script>
function parse(){
var msg=document.getElementById("a").innerHTML;
var form = document.getElementsByTagName("form")[0]
msg = form.getElementsByClassName("input_field")[0].value;//this is to print res.
}
</script>
I added type="button" to the button to prevent the form from reloading the page

Use jsp by action button

i don't know why this code don't work correctly. I want print "AAAAA" only when i click in the button, but if i launch this and i click in the button, don't change nothing and the string is every time printed. Why don't work?
<html>
<head>
<link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="ISO-8859-1">
</head>
<body>
<%
if(request.getParameter("buttonName") != null) {
out.println("AAAAAA");
}
%>
<FORM NAME="form1" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="buttonName">
<INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
function button1()
{
document.form1.buttonName.value = "yes";
form1.submit();
}
</SCRIPT>
</body>
</html>

how to pass the values from one html page to another html page using javascript?

i am trying to pass the values from one html page to another html page but i am getting some errors..
below is my html page one code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function first() {
location.href = "onclick2.html";
}
</script>
</head>
<body>
<button onclick="first()" >Home</button>
<form action="onclick2.html" method="post">
<input type="text" name="sender" />
<input type="submit" value="send"/>
</form>
</body>
</html>
below is my html page 2 code
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function first() {
location.href = "onclick.html";
}
</script>
</head>
<body>
<button onclick="first()">Home2</button>
<form action="onclick.html" method="get">
<input type="text" name="reciver" />
</body>
you can pass value in url and transfer it as given below :
location.href = "http://www.domainname.com/login.html?FirstName=admin&LastName=admin"

Passing the Data from one to other in javascript

I have two HTML pages: firstpage.html and secondpage.html. In firstpage.html, there is a form-
firstpage.html:
<!DOCTYPE html>
<html>
<head>
<title>Form Filling</title>
</head>
<body>
<form action="secondpage.html" method="GET">
Enter Serial Number: <input type="number" name="serialNumber" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
The firstpage data is sent to secondpage.html. I want to display and use the form data serialNumber in secondpage.html-
secondpage.html:
<!DOCTYPE html>
<html>
<head>
<title>Display</title>
</head>
<body>
<form name="selva" action="thirdpage.html">
<input type="hidden" name="kumar">
</form>
<script type="text/javascript">
var locate=window.location;
document.selva.kumar.value=locate;
var text=document.selva.kumar.value;
function pass(str)
{
point=str.lastIndexOf('=');
return(str.substring(point+1,str.length));
}
document.write("Serial Number" + pass(text));
</script>
</body>
</html>
So now I can pass the serialNumber variable from firstpage.html to secondpage.html so that the above code in secondpage.html will show the serial nuimber, and I want same serial number in at thirdpage-
thirdpage.html:
<!DOCTYPE html>
<html>
<head>
<title>Repeating</title>
</head>
<body>
<form method="link">
Enter Serial Number2: <input type="number" name="burns" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
please tell how to print a data in all those pages?
The simplest method I could find for this is, write all the three pages in a single html file and display them based on conditions. This way you dont need to use localstorage.
Other method will be to use query parameters. You can simply learn how to use them. Here's the link to simple javascript-handled query params plugin:
http://jillix.github.io/url.js/
You can pass the serial no as a query parameter to another html. If you are confused on how to use this method, let me know and I'll tell you in detail.

Categories

Resources