admin管理员组文章数量:1345707
I want to redirect a page after validation. I have the ff. EXAMPLE:
form.html:
<form method="post" action="" enctype="multipart/form-data" onsubmit="return checkform(this);">
<p><span style="width:180px">Username: </span><input type="text" name="username" id='un'></p>
<p><span style="width:180px">Password: </span><input type="password" name="password" id='pw'></p>
<input type="submit" value="SUBMIT" />
</form>
script:
<script type='text/javascript'>
function checkform(){
if(document.getElementById("un").value == 'jayem30' && document.getElementById("pw").value == 'jayem' ){
alert("Login Successful");
window.location = "/"
}else{
alert("Access denied. Valid username and password is required.");
}
}
</script>
I tried this but it does not redirect to google. Many thanks for any help! :)
I want to redirect a page after validation. I have the ff. EXAMPLE:
form.html:
<form method="post" action="" enctype="multipart/form-data" onsubmit="return checkform(this);">
<p><span style="width:180px">Username: </span><input type="text" name="username" id='un'></p>
<p><span style="width:180px">Password: </span><input type="password" name="password" id='pw'></p>
<input type="submit" value="SUBMIT" />
</form>
script:
<script type='text/javascript'>
function checkform(){
if(document.getElementById("un").value == 'jayem30' && document.getElementById("pw").value == 'jayem' ){
alert("Login Successful");
window.location = "http://www.google./"
}else{
alert("Access denied. Valid username and password is required.");
}
}
</script>
I tried this but it does not redirect to google.. Many thanks for any help! :)
Share asked May 11, 2011 at 3:35 KrisKris 3,77916 gold badges52 silver badges67 bronze badges3 Answers
Reset to default 4Try putting redirect in a timeout. Works like a charm
setTimeout(function() {window.location = "http://www.google./" });
By the way, instead of
onsubmit="return checkform(this);"
use
onsubmit="return(checkform())"
because IE doesn't like when you ommit ( and ).
try document.location.href instead of window.location
Try out this method to redirect page after validation.
syntax:
window.location.assign("url")
example:
<script type='text/javascript'>
function checkform(){
if(document.getElementById("un").value == 'jayem30' && document.getElementById("pw").value == 'jayem' ){
alert("Login Successful");
window.location.assign("http://www.google./")
}else{
alert("Access denied. Valid username and password is required.");
}
}
</script>
This is a working method.
本文标签: htmlJavaScript How to redirect a page after validationStack Overflow
版权声明:本文标题:html - JavaScript: How to redirect a page after validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743773818a2536604.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论