Javascript if if else not working [英] Javascript if and else not working
问题描述
我知道这是我,但我不能让这个条件起作用。无论
支票或信用卡它总是默认为脚本的其他部分。
如果(login.PMT_INDICATOR.value ==" C")我无法获得;) 是真实的。我是什么
做错了?请帮助
< html>
< form method =" post"名称= QUOT;登录" ID = QUOT;登录" >
< input type =" hidden"值=帐户余额
name =" PMT_TYPE_DESC" >
< input type =" radio"值="" name =" PMT_INDICATOR" Check
(支票/储蓄帐户)< p>
]< input type =" radio"值=C checked name =" PMT_INDICATOR" >
信用卡< / p>< p>
<输入类型=按钮名称= submit1 value ="登录"
Onclick =" SubmitForm(login);">
< / p>
< / form>
< script type =" text / javascript">
<! -
函数SubmitForm(登录)
{
if(login.PMT_INDICATOR.value ==" C")
{
login.action =" https://creditcard.gateway.com/Gateway.aspx" ;;
}
else
{
login.action =" https://Check.gateway.com/Gateway.aspx" ;;
}
login.submit(); //提交页面
返回true;
}
// - >
< / script>
< / html>
I know it is me but i can not get this condition to work. Regardless of
Check or credit card it always defaults to else portion of the script.
I can''t get if (login.PMT_INDICATOR.value == "C") to be true. What i am
doing wrong? please help
<html>
<form method="post" name="login" id="login" >
<input type="hidden" Value ="Account Balance"
name="PMT_TYPE_DESC" >
<input type="radio" Value ="" name="PMT_INDICATOR"Check
(Checking/Saving Account)<p>
] <input type="radio" Value ="C" checked name="PMT_INDICATOR" >
Credit Cards</p><p>
<input type=button name=submit1 value="Login"
Onclick="SubmitForm(login);">
</p>
</form>
<script type="text/javascript">
<!--
function SubmitForm(login)
{
if (login.PMT_INDICATOR.value == "C")
{
login.action = "https://creditcard.gateway.com/Gateway.aspx";
}
else
{
login.action = "https://Check.gateway.com/Gateway.aspx";
}
login.submit(); // Submit the page
return true;
}
//-->
</script>
</html>
推荐答案
SA SA写道:
SA SA wrote:
我知道这是我,但我不能让这个条件起作用。无论
的支票或信用卡,它总是默认为
脚本的其他部分。我不能得到if(login.PMT_INDICATOR.value ==" C")为真。
我做错了什么?请帮助
I know it is me but i can not get this condition to work. Regardless
of Check or credit card it always defaults to else portion of the
script. I can''t get if (login.PMT_INDICATOR.value == "C") to be true.
What i am doing wrong? please help
使用:
document.login.PMT_INDICATOR.value
或者:
document.forms [''login'']。elements [''PMT_INDICATOR'']。value
JW
Use:
document.login.PMT_INDICATOR.value
Or:
document.forms[''login''].elements[''PMT_INDICATOR''].value
JW
Janwillem Borleffs写道:
Janwillem Borleffs wrote:
document.forms [''login'']。elements [''PMT_INDICATOR ''] .value
document.forms[''login''].elements[''PMT_INDICATOR''].value
OTOH,您可以通过将对submitForm的调用更改为:
< input type = button name = submit1 value =" Login"
Onclick =" SubmitForm(this.form);"
JW
OTOH, you could fix it by changing the call to submitForm into:
<input type=button name=submit1 value="Login"
Onclick="SubmitForm(this.form);">
JW
SA SA说:
SA SA said:
>
我知道这是我,但我不能让这个条件起作用。无论是支票还是信用卡,它总是默认为脚本的其他部分。
如果(login.PMT_INDICATOR.value ==" C")是真的,我就得不到。我做错了什么?请帮助
>
I know it is me but i can not get this condition to work. Regardless of
Check or credit card it always defaults to else portion of the script.
I can''t get if (login.PMT_INDICATOR.value == "C") to be true. What i am
doing wrong? please help
如果您认为某个表达式应该是真的,请不要添加警报()
来告诉您什么价值确实如此。
在这种情况下:
alert(login.PMT_INDICATOR.value)
将告诉你价值永远不是C。
-
If an expression that you think should be true, isn''t, add an alert()
to show you what the value really is.
In this case:
alert(login.PMT_INDICATOR.value)
will show you that the value is never "C".
--
这篇关于Javascript if if else not working的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!