How to transfer form values ​​One html page to another javascript html page?

How to transfer values ​​from one html page to another html javascript page

For instance:

Page1.html page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>arasu</title> <style type="text/css"> #popupbox{ margin: 0; margin-left: 40%; margin-right: 40%; margin-top: 50px; padding-top: 10px; width: 20%; height: 150px; position: absolute; background: #FBFBF0; border: solid #000000 2px; z-index: 9; font-family: arial; visibility: hidden; } </style> <script language="JavaScript" type="text/javascript"> function login(showhide){ if(showhide == "show"){ document.getElementById('popupbox').style.visibility="visible"; }else if(showhide == "hide"){ document.getElementById('popupbox').style.visibility="hidden"; } } </script> </head> <body> <div > <form name="login" action="AgaramAnimation.html" method="get"> <center>Username:</center> <center><input name="username" size="14" /></center> <center>Password:</center> <center><input name="password" type="password" size="14" /></center> <center><input type="submit" name="submit" value="login" /></center> </form> </div> </body> </html> 

here I enter two values: username and password, when I click the "Send" button, the popup closes, and the values ​​are transferred to another java script page indicated below.

Page2.html

 function gettingvalues() { var connection = new ActiveXObject("ADODB.Connection"); var connectionstring = "Data Source="";Initial Catalog="";User ID="";Password="";Provider="""; connection.Open(connectionstring); var rs = new ActiveXObject("ADODB.Recordset"); rs.Open("select * from logindetails where username='" **+ username +** "' and password= '" **+ password +** "'", connection); if (!rs.eof) { document.getElementById("").innerHTML = ""; } else { alert('please enter valid username and password'); } connection.close; } 

Help me..........

+6
source share
3 answers

Assuming your two pages are in the same domain, you can use localStorage.

Popup.html:

 var user = prompt('user name', ''); var password = prompt('password', ''); localStorage.user = user; localStorage.password = password; 

Then return to the main page:

 var user = localStorage.user; var password = localStorage.password; 

Note 1 I will not comment on security (except, of course, do not do this, as I did it above!)

Note 2 : localStorage only supports about 92%: http://caniuse.com/namevalue-storage

+2
source

If Main.html opened Popup.html using window.open() , then on the page Popup.html there may be a link to its opening window ( Main.html window) using window.opener . That way, he can call the setCredentials callback function defined in Main.html using

 window.opener.setCredentials(...); 

Example:

in Main.html:

 // callback function called by the popup function setCredentials(login, password) { // do what you want with the login and password } 

in popup.html

 // function called when the form is submitted function login(login, password) { window.opener.setCredentials(login, password); window.close(); } 
0
source

You can access the window that opened a new window (called the parent window) through window.parent , and then execute your javascript using this object.

Here is an example of forcing a parent page to refresh using this: [1] Forcing a parent page to refresh via javascript

So, in your case, you could say the variables for username and password in js like this, and you can set them in a popup like this:

 //parent window username = ""; password = ""; .... //popup window window.parent.username = enteredUsername; window.parent.password = enteredPassword; 
0
source

Source: https://habr.com/ru/post/904015/


All Articles