473,385 Members | 1,326 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,385 software developers and data experts.

If value of text field

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
4 1471
JosAH
11,448 Expert 8TB
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
3,112 Expert 2GB
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
1,216 Expert 1GB
Moved to the correct forum...
Jul 8 '08 #4
acoder
16,027 Expert Mod 8TB
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

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

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
4
by: Semi Head | last post by:
Hello folks, I'm looking for a script to validate a specific number value in a standard form input field. An example would be, if someone enters a number into a form input, I want the script to...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
7
by: turtle | last post by:
I want to find out the max value of a field on a report if the field is not hidden. I have formatting on the report and if the field doesn't meet a certain criteria then it is hidden. I want to...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
2
by: Coll | last post by:
I have a field that I would like to display on a report only if the value of another field matches a certain criteria. If it does match I need the label & the field value to display (though I'm...
4
by: AR123 | last post by:
In the field for employee contribution I want to have GBP and make sure that this prints out in the results email. How can I set it up so that the GBP display next to the value in the results email?...
3
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.