如何使表单仅针对我选择的单词提交

How do I make a form submit only for the word of my choosing

本文关键字:选择 单词 提交 何使 表单      更新时间:2023-09-26

我有一个登录页面。 我希望表单验证表单以允许表单提交,如果我只输入用户名的特定单词和我选择的密码的不同单词。 我不想使用 sql 数据库。 我希望它验证为我预设的特定单词。如果正确,我希望它在我点击提交后将我重定向到我的索引.htm页面。 但如果它是错误的,我希望它清除文本字段。 我使用什么代码来执行此操作。这是我的代码的基本布局:

.html

<body>
<h1 class="color">Login</h1>
<form action="index.htm">
<span class="heading">Username:</span><br>
<input name="username" type="text" id="username" size="20">
<br>
<span class="heading">Password:</span><br>
<input name="password" type="password" id="password" size="10"><br>

<button name="Login" type="submit" onclick = "evaluateInput()">Login</button>
</form>
</body>

.js

evaluateInput = function(){
     inputBox = document.getElementById("username");
     if(inputBox.value == "<insert password here>"){
     }else
     }
 }{
     inputBox = document.getElementById("password");
     if(inputBox.value == "<insert password here>"){
     }else
     }
 }

如果您成功验证了上面注释掉的表单,则可以使用以下代码进行重定向。

window.location.href = "index.html"

编辑

evaluateInput = function(){
    inputUsername = document.getElementById("username");
    inputPassword = document.getElementById("password");
    if(inputUsername.value == "<insert username here>" && inputPassword.value == "<insert password here>"){
        window.location.href = "index.html"
    }
 }