By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,481 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,481 IT Pros & Developers. It's quick & easy.

If value of text field

P: 2
Hi,

I have the following code written...

Expand|Select|Wrap|Line Numbers
  1. Totamt = 
  2.      eval(TotA) +
  3.      eval(TotB) +
  4.      eval(TotC) +
  5.      eval(TotD) ;
  6.  
  7.      if (Code =="ABC")
  8.         {Discount = Totamt * .05};
  9.         Totamt = Totamt - Discount;
  10.  
  11.     if (eval(Totamt) > 75)
  12.         {Discount = Totamt * .1};
  13.         Totamt = Totamt - Discount;
  14.  
Apart from my form calculating the sums of Products A, B, C & D, if the value entered into the field 'Code' =ABC, I want the Discount amt of 5% to be applied - however once I have added this field, I no longer get an order total, no matter whether the order is > 75, OR the 'code' of ABC is entered.

Being a complete novice to javascript, can somebody tell me where I am going wrong?

Thanks.
Jul 6 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 10K+
P: 11,448
if (Code =="ABC")
You can't compare Strings using the == operator; as a matter of fact you can't
compare any object value using that operator. The == operator compares the
object references, not their values. You have to use the equals() method for that:

Expand|Select|Wrap|Line Numbers
  1. if (Code.equals("ABC"))
  2.  
btw, there's a convention that all variables and methods start with a lower case
letter; classes, interfaces and enumerations start with an upper case letter. Better
stick to that convention.

kind regards,

Jos
Jul 6 '08 #2

Nepomuk
Expert 2.5K+
P: 3,112
Being a complete novice to javascript, can somebody tell me where I am going wrong?
One thing would be: Java is not JavaScript.
It's a common mistake. So, if you actually mean JavaScript, the JavaScript Forum is here. Otherwise, you're right here. :-)

Greetings,
Nepomuk
Jul 6 '08 #3

BigDaddyLH
Expert 100+
P: 1,216
Moved to the correct forum...
Jul 8 '08 #4

acoder
Expert Mod 15k+
P: 16,027
Apart from my form calculating the sums of Products A, B, C & D, if the value entered into the field 'Code' =ABC, I want the Discount amt of 5% to be applied - however once I have added this field, I no longer get an order total, no matter whether the order is > 75, OR the 'code' of ABC is entered.
Post the HTML code and how you're calling the function.

Please use code tags when posting code (see How to Ask a Question). Thanks!
Jul 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.