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

Need help with greater than if statement

18
I'm trying to write an if statement to see if the answer I just entered is larger than the answer on the previous page.
But let's say the 1st number is 50 and the 2nd is 9. The alert comes up because the "9" is bigger than the "5" in 50.
How can I make this work?

I have a hidden field that is bringing the answer from page 1 to page 2.
[HTML]
<input type="hidden" name="Q1" value="$Q1">[/HTML]

This is my if statement:

Expand|Select|Wrap|Line Numbers
  1. answerA = document.forms[0].Q1.value 
  2. answerB = document.forms[0].Q2.value 
  3.  
  4.  if (answerB > answerA)
  5.       {
  6.     alert("\"Please enter a smaller number.")
  7.     FormQ2.Q2.focus(); 
  8.     return false;
  9.     } 
Please help if you can. Thanks :)
Nov 20 '08 #1
5 1366
gits
5,390 Expert Mod 4TB
just parseInt() or parseFloat() the values before comparing them ...

kind regards
Nov 20 '08 #2
help4me
18
If I put this . . .

Expand|Select|Wrap|Line Numbers
  1. parseInt (answerA)
  2. parseInt (answerB)
  3.  
  4.   if (answerB > answerA)
  5.       {
  6.     alert("\"Please enter a smaller number.")
  7.     FormQ2.Q2.focus(); 
  8.     return false;
  9.     }   
  10.  

. . . the error comes up for any number entered. Do I need to do something other than just put in parseInt()?
Nov 20 '08 #3
gits
5,390 Expert Mod 4TB
the usage should be like the following:

Expand|Select|Wrap|Line Numbers
  1. answerA = parseInt(document.forms[0].Q1.value);
the functioncall doesn't change the value itself ... you have to assign the value back to a variable like in the given example ...

kind regards
Nov 20 '08 #4
help4me
18
Thanks for your help! I got it.
Dec 4 '08 #5
gits
5,390 Expert Mod 4TB
no problem ... you're welcome. post back to the forums anytime you have more questions ;)

kind regards
Dec 5 '08 #6

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

Similar topics

0
by: Gary Stollman | last post by:
My Father is a Clone//ETs plotting to overthrow the human race! On August 19, 1987 a gun-carrying Gary Stollman entered the studio of Los Angeles's KNBC television, crashing consumer reporter...
0
by: richardkreidl | last post by:
What I'd like to do is to check the values in an element if they're greater than a certain time and if they are, then change the font color of the time. I have about 10 elements that I will check...
8
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ......
7
by: Buck Rogers | last post by:
Hi all! Newbie here. Below is an example from Teach Yourself C in 21 Days. My apologies if it is a bit long. What I don't understand is how the "get_data" function can call the...
2
by: wing ver ka gundam | last post by:
THanks~ this is the example and my quote are below Write a program in JAVA that allows the user to input 5 ints. The program will then output these five values in reverse order. The program will...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
1
by: jiggaman828 | last post by:
Am I doing something wrong with setting my width? I thought I had it correct. Can any inform me on how to write 4 different while or do-while loops counting down to 0, it has to be lined up column...
2
by: itsmee | last post by:
I have a couple of issues with this program: 1. i'm not sure on how to write so that if the users_num is greater than 21 it should ask if the user would want to play again. i tried putting break;...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
1
by: ciojr | last post by:
how do i write a sql (ORACLE) statement for where the first word in the name field is greater than 17 chars? if i do this SELECT businessname FROM tablename WHERE LEN(businessname) 17; it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.