1

good Evening friends, i'm trying to make a simple javaScript code that send the inputs information to another html page, and its not working for me.

i've 2 pages page1.html that contains the inputs :

<html>
<head>
<link href="smi.css" rel="stylesheet"  type="text/css"> </head>
<body> 

<form action="page2.html" method="post">

Tape your firstname: <input type="text" name="nom"><br>
Tape your lastname: <input type="text" name="prenom"><br>
<button type="submit">gènèrer</button>

</form>
</body>
</html>

and the page2.html :

<html>
<head>
<link href="smi.css" rel="stylesheet"  type="text/css"> </head>
<body> 

<p id="zone" ></p>

<script src="page2.js" type="text/JavaScript"> </script>

</body>
</html>

this is my script :

var x = getUrlVars()["nom"];
var y = getUrlVars()["prenom"];
var w = getUrlVars()["Tel"];

var z = "bonjour " +x+" "+y+"votre Tel est : " +w;
document.getElementById("zone").innerText() = z;


function getUrlVars(){

var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m,key,value){
vars[key] = value;
});
return vars;
}

i hope if u can help me plz.

2
  • 1
    You need some server-side code to add the values to the page send as the response. ... or use GET instead of POST as the request method. Commented Dec 17, 2019 at 19:26
  • 1
    try using epress the Node.js framework. For this type of tasks u need some backend code, usually it is handled by a server ( your computer con do this work too ), google it u will find many usefull things Commented Dec 17, 2019 at 19:30

1 Answer 1

2

What @teemu said about using server side code, but you can also do something like this while learning basic HTML:

Add a page1.js with something like this:

function submit(){
   let fName = //get first name;
   let lName = //get last name
   location.href(`page2.html/fName=${fName}&lName=${lName}`);
}

Then call this function from the onsubmit button:

<button onClick="submit();">gènèrer</button>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.