使用javascript重定向 [英] Redirect with javascript

查看:51
本文介绍了使用javascript重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用javascript重定向?我使用javascript对表单进行了一些验证,但是在单击提交按钮后,表单被设置为重定向回

索引页面。所以我想要做什么

是说它是否通过验证,然后重定向,但如果它没有通过
,我希望它留在页面上所以用户可以解决问题

并再次点击提交。我可以在javascript中执行此操作吗?


-

KL

解决方案



" KL" < kl ******* @ bermail.com的gmail.comschreef

新闻:11 ******************** @ p79g2000cwp。 googlegrou ps.com ...


有没有办法用javascript重定向?我使用javascript对表单进行了一些验证,但是在单击提交按钮后,表单被设置为重定向回

索引页面。所以我想要做什么

是说它是否通过验证,然后重定向,但如果它没有通过
,我希望它留在页面上所以用户可以解决问题

并再次点击提交。我可以在javascript中执行此操作吗?


-

KL



函数验证( ){

if(it_validated){

返回true

}否则{

alert("你忘了)填写....;;

返回false

}

}


< form action =" the_index_page.php"方法= QUOT;交" onsubmit =" return

validate()">

< input type =" submit" value =" submit">

< / form>




Marc写道:


" KL" < kl ******* @ bermail.com的gmail.comschreef

新闻:11 ******************** @ p79g2000cwp。 googlegrou ps.com ...


有没有办法用javascript重定向?我使用javascript对表单进行了一些验证,但是在单击提交按钮后,表单被设置为重定向回

索引页面。所以我想要做什么

是说它是否通过验证,然后重定向,但如果它没有通过
,我希望它留在页面上所以用户可以解决问题

并再次点击提交。我可以在javascript中执行此操作吗?


-

KL



函数验证( ){

if(it_validated){

返回true

}否则{

alert("你忘了)填写....;;

返回false

}

}


< form action =" the_index_page.php"方法= QUOT;交" onsubmit =" return

validate()">

< input type =" submit" value =" submit">

< / form>



感谢您回复Mark,但我很困惑。如果我以这种方式使用

中的操作...如何获取

表单上提交的信息给我?现在,我的托管服务已经使用了

action =" gdform.asp"并且它会通过电子邮件向我发送我在表格上收集的信息




-

KL


>


感谢您回复Mark,但我很困惑。如果我以这种方式使用

中的操作...如何获取

表单上提交的信息给我?现在,我的托管服务已经使用了

action =" gdform.asp"这使我通过电子邮件向我发送了表格上收集的信息




-

KL



现在你让我感到困惑...

你想从javascript访问信息吗?


函数验证( ){

if(document.getElementById(" info1")。value ==""&&

document.getElementById(" info1") .value ==""){

alert("你忘了填写info1和info2");

返回false

} else {

返回true

}

}


< form action =" ; gdform.asp"方法= QUOT;交" onsubmit =" return validate()">

< input type =" text" ID = QUOT; INFO1"名称= QUOT; INFO1"值信息>

< input type =" text" ID = QUOT; INFO2"名称= QUOT; INFO2"值更多信息...>


< input type =" submit" value =" submit">

< / form>


Is there a way to redirect with javascript? I used javascript to do
some validation on a form, but the form was set to redirect back to the
index page after the submit button was clicked. So what I want to do
is to say if it passes validation, then redirect, but if it doesn''t
pass, I want it to stay on the page so the user can fix the problems
and click submit again. Can I even do this in javascript?

--
KL

解决方案


"KL" <kl*******@gmail.comschreef in bericht
news:11********************@p79g2000cwp.googlegrou ps.com...

Is there a way to redirect with javascript? I used javascript to do
some validation on a form, but the form was set to redirect back to the
index page after the submit button was clicked. So what I want to do
is to say if it passes validation, then redirect, but if it doesn''t
pass, I want it to stay on the page so the user can fix the problems
and click submit again. Can I even do this in javascript?

--
KL

function validate(){
if (it_validated){
return true
}else{
alert("You forgot to fill out....");
return false
}
}

<form action="the_index_page.php" method="post" onsubmit="return
validate()">
<input type="submit" value="submit">
</form>



Marc wrote:

"KL" <kl*******@gmail.comschreef in bericht
news:11********************@p79g2000cwp.googlegrou ps.com...

Is there a way to redirect with javascript? I used javascript to do
some validation on a form, but the form was set to redirect back to the
index page after the submit button was clicked. So what I want to do
is to say if it passes validation, then redirect, but if it doesn''t
pass, I want it to stay on the page so the user can fix the problems
and click submit again. Can I even do this in javascript?

--
KL


function validate(){
if (it_validated){
return true
}else{
alert("You forgot to fill out....");
return false
}
}

<form action="the_index_page.php" method="post" onsubmit="return
validate()">
<input type="submit" value="submit">
</form>

Thanks for replying Mark, but I am confused. If I use the action in
this manner...how do I get the information that was submitted on the
form to me? As it stands right now, my hosting service has my using
action="gdform.asp" and that makes it email me the information
collected on my form.

--
KL


>

Thanks for replying Mark, but I am confused. If I use the action in
this manner...how do I get the information that was submitted on the
form to me? As it stands right now, my hosting service has my using
action="gdform.asp" and that makes it email me the information
collected on my form.

--
KL

Now you got me confused...
You want to access the information from javascript?

function validate(){
if (document.getElementById("info1").value == "" &&
document.getElementById("info1").value == ""){
alert("You forgot to fill out info1 and info2");
return false
}else{
return true
}
}

<form action="gdform.asp" method="post" onsubmit="return validate()">
<input type="text" id="info1" name="info1" value"the information">
<input type="text" id="info2" name="info2" value"more information...">

<input type="submit" value="submit">
</form>


这篇关于使用javascript重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆