Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement does not function correctly

Status
Not open for further replies.

RoseDa

MIS
Joined
Aug 26, 2004
Messages
12
Location
US
I am very new at Javascript, so this may be to simple for most. Sorry, but I am trying to learn this stuff.

I have a form that has several drop downs for users to select a number from 0 - 100.
Example:
Code:
<select name="Ami"  onchange="GetTotal()">
   <option value=0>0 <option value=10>10 </select>

I then add the all the drop down numbers with javascipt.
First I assign each name a variable.
Example:
Code:
<var Ami = document.week1.Ami.value;

Then I add all the variables together for a total.
Example:
Code:
<var Gtotal = ((-Ami - Bob)* -1);
I probably did this incorrectly, but it works.

Then I make the total equal a form element.
I would like to put in an validation or if statement that would warn the user if the total was over 100.

I tried this but it did not work:
Code:
<if (Gtotal > 100) {"alert('Total can not be more than 100!');"} else {document.week1.total.value = Gtotal};

Any assistance would be greatly appreaciated.

Yours,
Dale Rose
 
cut the leading "<" and put this in the function, if it is not already.

--Chessbot
 
Chessbot,
Thank you for the quick response, but the leading "<" is not part of the code. For some reason by placing the code in code tags it adds the < to the front of it. The if statement is:

if (Gtotal > 100) {"alert('Total can not be more than 100!');"} else {document.week1.total.value = Gtotal};

I tested the alert statement separatly and it works and the else statement works also.

What am I missing?

Yours,
Dale Rose
 
Code:
{"alert('Total can not be more than 100!');"}
cut the quotes around the alert, i.e:
Code:
{alert('Total can not be more than 100!');}

--Chessbot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top