简体   繁体   English

如何使用保存在另一个html文件中的数组中的表单数据

[英]how to use form data saved in an array in another html file

im having a project in which there is an html file for sign up and another one for login. 即时通讯有一个项目,其中有一个用于注册的html文件和另一个用于登录的文件。 So i am storing the data from the sign up form in some arrays and i want to use them in the login file but the arrays seems to be empty. 所以我将注册表单中的数据存储在某些数组中,我想在登录文件中使用它们,但数组似乎为空。 Is there somekind of global array in javascript or something like that? 在javascript中是否存在某种全局数组? Thanks in advance :) My javascript code is: 在此先感谢:)我的JavaScript代码是:

var usernames=[]; //login usernames
var passwords=[]; //login passwords
var personUsr = []; //signup usernames
var personPass = []; //signup passwords

function insert(){ //login onclick function
 var usernameValue = document.getElementById('username').value;
 var passwordValue = document.getElementById('password').value;

 usernames[usernames.length]=usernameValue;
 passwords[passwords.length]=passwordValue;

 document.getElementById('username').value="";
 document.getElementById('password').value="";
 for(var i = 0; i < personUsr.length; i++) {
   if(titleValue===personUsr[i]){
       alert("user found"); }
   else{
       alert("no user with that username");}      
    }
 }


function submitSignUp(){ //signup onclick function

    var firstName = signupform.elements["firstname"].value;
    var lastName = signupform.elements["lastname"].value;
    var country = signupform.elements["countrySel"].selectedIndex.value;
    var user = signupform.elements["username"].value;
    var pass = signupform.elements["password"].value;
    var repass = signupform.elements["password2"].value;

    personUsr[personUsr.length]=user;
    personPass[personPass.length]=pass;         
 }  

AJAX is built for this purpose. 为此目的构建了AJAX。 If you want to post javascript variable to other page you should use ajax. 如果要将JavaScript变量发布到其他页面,则应使用Ajax。

Else you can use a sever-side technique to do this 否则,您可以使用服务器端技术来执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用HTML表单将数据发送到javascript以另存为变量 - How to use a html form to send data to javascript to be saved as a variable 如何从 html 文件中获取保存的数据? - How to get saved data from html file? 如何使用一个HTML文件中的表格中的值以另一HTML文件中的形式使用 - How to use a value from a table in one html file in a form that is in another html file 如何使用本地存储将数据发送到另一个HTML文件(NOT SPA)-angularjs - How to use localstorage to send data into another html file(NOT SPA) - angularjs 移至新的HTML页面后,如何使用保存在Javascript文件中的已保存变量? - How to use saved variables saved in Javascript file after moving to new HTML page? 如何将类似数组的数据从HTML文件发送到另一个HTML页面? - How do I send data like an array from an html file to another html page? 通过HTML表单将JavaScript数组传递到另一个js文件 - Passing a javascript array through HTML form to another js file JQuery和HTML:如何使用echo $ _POST将数据从一个表单获取到另一个表单 - JQuery & HTML: How to use echo $_POST to get data from one form to another 如何保存 HTML FORM 数据以供将来使用 - How to save a HTML FORM data to use in future 如何将html表单数据发送到excel文件 - How to send html form data to excel file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM