473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Javascript if and else not working

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>

Dec 19 '06 #1
12 2293
SA SA wrote:
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
Use:

document.login.PMT_INDICATOR.value

Or:

document.forms['login'].elements['PMT_INDICATOR'].value
JW

Dec 19 '06 #2
Janwillem Borleffs wrote:
document.forms['login'].elements['PMT_INDICATOR'].value
OTOH, you could fix it by changing the call to submitForm into:

<input type=button name=submit1 value="Login"
Onclick="SubmitForm(this.form);">
JW
Dec 19 '06 #3
Lee
SA SA said:
>
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
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".
--

Dec 19 '06 #4
JW,
I am using form id instead of this.form which i think i almost the
same. I tried that before. It is not that. Any other idea.
sa

Janwillem Borleffs wrote:
Janwillem Borleffs wrote:
document.forms['login'].elements['PMT_INDICATOR'].value

OTOH, you could fix it by changing the call to submitForm into:

<input type=button name=submit1 value="Login"
Onclick="SubmitForm(this.form);">
JW
Dec 20 '06 #5
Lee,
When i did that it tells me PMT_INDICATOR is undefined. It tried this
but did not work either.

<form id="login" name="login" method="post"><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" checked value="C" name="PMT_INDICATOR"Credit
Cards</p>

<p><input onclick="SubmitForm(this.form, login.PMT_INDICATOR.value);"
type="button" value="Login" name="submit1"></p>
</form>
<script type="text/javascript">
<!--

function SubmitForm(login, PMT_INDICATOR)
{
var pmt = PMT_INDICATOR
if (pmt == "C")
{
alert(pmt)
login.action = "https://creditcard.gateway.com/Gateway.aspx";
}
else
{
alert(pmt)
login.action = "https://Check.gateway.com/Gateway.aspx";
}
login.submit(); // Submit the page
return true;
}

//-->
</script>


Lee wrote:
SA SA said:

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

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".
--
Dec 20 '06 #6
<input type="radio" value="" name="PMT_INDICATOR"Check
(Checking/Saving Account)
<input type="radio" checked value="C" name="PMT_INDICATOR"Credit
Cards

After taking this a part, it turns out the problem is with two check
boxes with same name. is there any way to get around this problem?

thanks

Dec 20 '06 #7
SA SA said the following on 12/19/2006 10:37 PM:
<input type="radio" value="" name="PMT_INDICATOR"Check
(Checking/Saving Account)
<input type="radio" checked value="C" name="PMT_INDICATOR"Credit
Cards

After taking this a part, it turns out the problem is with two check
boxes with same name.
I don't even see one checkbox, much less two.
is there any way to get around this problem?
What problem?

<URL: http://jibbering.com/faq/index.html#FAQ4_13>
<URL: http://www.jibbering.com/faq/faq_notes/form_access.html#faBut>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '06 #8
meant to say radio buttons.
sa
Randy Webb wrote:
SA SA said the following on 12/19/2006 10:37 PM:
<input type="radio" value="" name="PMT_INDICATOR"Check
(Checking/Saving Account)
<input type="radio" checked value="C" name="PMT_INDICATOR"Credit
Cards

After taking this a part, it turns out the problem is with two check
boxes with same name.

I don't even see one checkbox, much less two.
is there any way to get around this problem?

What problem?

<URL: http://jibbering.com/faq/index.html#FAQ4_13>
<URL: http://www.jibbering.com/faq/faq_notes/form_access.html#faBut>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '06 #9
SA SA wrote:
After taking this a part, it turns out the problem is with two check
boxes with same name. is there any way to get around this problem?
Yes, but you have many more problems than just that.
Try this, which includes several fixes [untested]:

<form id="login" name="login" method="post"
action="https://Check.gateway.com/Gateway.aspx"
onsubmit="return checkform(this)">
<input type="hidden" value="Account Balance" name="PMT_TYPE_DESC">
<input type="radio" value="" name="PMT_INDICATOR"Check (Checking/Saving
Account)
<input type="radio" checked value="C" name="PMT_INDICATOR"Credit Cards
<input type="submit" onclick="SubmitForm(this.form,
login.PMT_INDICATOR.value);" type="button" value="Login" name="submit1">
</form>

<script type="text/javascript">
function checkform(f) {
if (f.PMT_INDICATOR[0].checked) {
f.action = "https://creditcard.gateway.com/Gateway.aspx";
}
return true;
}
</script>

But, as a general rule, changing the action attribute of a form points to
bad design. If script is disabled, for example, your form breaks. Business
logic should be done on the server side.

As a final suggestion, see
http://www.javascripttoolbox.com/bestpractices/#forms

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Dec 20 '06 #10
Lee
SA SA said:
>
<input type="radio" value="" name="PMT_INDICATOR"Check
(Checking/Saving Account)
<input type="radio" checked value="C" name="PMT_INDICATOR"Credit
Cards

After taking this a part, it turns out the problem is with two check
boxes with same name. is there any way to get around this problem?
They're radio boxes, and the Radio object doesn't have a "value" attribute.
See the FAQ regarding how to access the values of form elements.
--

Dec 20 '06 #11
In comp.lang.javascript message
<11**********************@73g2000cwn.googlegroups. com>, Tue, 19 Dec 2006
14:17:11, SA SA <su*******@gmail.comwrote:
>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
>if (login.PMT_INDICATOR.value == "C")
{
login.action = "https://creditcard.gateway.com/Gateway.aspx";
}
else
{
login.action = "https://Check.gateway.com/Gateway.aspx";
}
Clearly you have made a mistake.

Since you think the conditional statement is not working, examine the
condition. Probably "C" is safe, so put before that line

alert(login.PMT_INDICATOR.value)

to see what value the left side actually has. You will, I think, see
that its value is always "undefined".

So your REAL problem is that you have no notion of elementary debugging.

<URL:http://www.merlyn.demon.co.uk/js-other.htm#Dbg>

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 20 '06 #12
I am full time DBA, never touch this before. I was given two gateways
by our payment processing company. I was asked to post hidden
attributes to a gateway based upon credit or check payment.

All i need is:

1. Check
2. Credit

if 1 then
post to = "credit gateway"
else
post to = "Check Gateway"

I got Matt's suggestion to work with my need. I will trash my idea and
run with his.

sa



Dr J R Stockton wrote:
In comp.lang.javascript message
<11**********************@73g2000cwn.googlegroups. com>, Tue, 19 Dec 2006
14:17:11, SA SA <su*******@gmail.comwrote:
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

if (login.PMT_INDICATOR.value == "C")
{
login.action = "https://creditcard.gateway.com/Gateway.aspx";
}
else
{
login.action = "https://Check.gateway.com/Gateway.aspx";
}

Clearly you have made a mistake.

Since you think the conditional statement is not working, examine the
condition. Probably "C" is safe, so put before that line

alert(login.PMT_INDICATOR.value)

to see what value the left side actually has. You will, I think, see
that its value is always "undefined".

So your REAL problem is that you have no notion of elementary debugging.

<URL:http://www.merlyn.demon.co.uk/js-other.htm#Dbg>

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 20 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
3
by: useenmelately | last post by:
Hello, I am working with asp.net 2.0 and have run into a problem with the custom validators. The client validation functions were originally written in vbscript, but as this is not compatible...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
3
by: safiratec | last post by:
Hi, I want to show a div depending of the value of a <select> option, using 2 functions hidediv() and showdiv() - it is working fine in firefox, but not in IE (tested with IE 6 and 7). <body...
31
by: ajos | last post by:
hi frnds, i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are...
20
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great...
6
The1corrupted
by: The1corrupted | last post by:
I don't know if this is the right forum or not, but right now, my Javascript, that is embedded in PHP, is not working! It works everywhere else but not here. HELP!! <?php $soldnumber=$_POST;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.