[英]i want button on which when click it first check the password if the password is abcd than shows the another submit button else show an alert
<form action="#" method="post" target="_blank">
<div id = "another sub">
</br>
<input type = "password" size = "25px" id="pswd">
</br>
</div>
<button><a href="table.html" target="_blank" onclick="checkAddress('password');" >Submit</a></button>
<script>
function checkAddress(field){
var val = document.getElementById("pswd").value;
if (val === "abcd"){
alert ("Matched");
}
else {
alert("Try for Next Time");
}
}
</script>
</form>
i have a form here in which it first check password than takes to the another page 我在这里有一个表单,在该表单中,它首先检查密码,而不是转到另一页
You have to Add your Script Tag below the form tag or you can add it at the end of the page before the body closing tag, make sure to include the js in the page 您必须将脚本标签添加到form标签下,或者可以将其添加到页面末尾的body结束标签之前,请确保将js包含在页面中
<form action="#" method="post" target="_blank">
<div id = "another sub">
</br>
<input type = "password" size = "25px" id="pswd">
</br>
</div>
<button onclick="checkAddress('password');">Submit</button>
</form>
<script>
function checkAddress(field){
var val = document.getElementById("pswd").value;
if (val === "abcd"){
alert ("Redirect To page if Matched Found");
window.location = "http://www.redirecturlhere.com/"
}
else {
alert("Try for Next Time");
}
}
</script>
In your case, you don't need <form>
and <a>
tags. 就您而言,您不需要<form>
和<a>
标记。 Just redirect when password is input correct. 只要输入正确的密码即可重定向。
function checkAddress(field) { var val = document.getElementById("pswd").value; if (val === "abcd") { alert("Matched"); document.location.href = 'table.html'; } else { alert("Try for Next Time"); } }
<div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress();">Submit</button>
Don't use a form to avoid the reload: 不要使用表格来避免重新加载:
function checkAddress(field) { var val = document.getElementById("pswd").value; if (val == "abcd") { alert("Matched"); location.href = "table.html"; } else { alert("Try for Next Time"); } }
<div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress()">Submit</button>
It would be wise to not use inline js, using a examplename.js file that is loaded would be better solution. 不使用内联js是明智的,使用已加载的examplename.js文件将是更好的解决方案。
function checkAddress(field) { var val = document.getElementById("pswd").value; if (val === "abcd") { alert("Matched"); document.location.href = 'table.html'; } else { alert("Try for Next Time"); } }
<div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress();">Submit</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.