SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: IF statement?
-
Jul 23, 2007, 06:07 #1
- Join Date
- Feb 2004
- Location
- Ashburn, VA
- Posts
- 47
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
IF statement?
I have several text fields on page that I would like to make calculations based on if there is a number input in one of the fields.
So, if the price field is populated, the sale price field would populate using a function to do the calculation.
Now, how do I write the code for this to occur? I know how to get the function to fire based on clicking a submit button, but not sure how to do it simply based on a number keyed into the one field.
Is this possible and if so, how? Thanks a ton.
-
Jul 23, 2007, 06:40 #2
- Join Date
- Jul 2006
- Location
- Leeds, UK
- Posts
- 38
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You'd need to;
1) get a reference to the price field
2) remove whitespace
3) check it's length is more than 0
4) check it is a number
5) if all's fine, do your calculation.
Hope that's on the right track, fairly rushed reply and am trying to imagine your form.
Hope it helps.
-
Jul 23, 2007, 06:47 #3
- Join Date
- Feb 2004
- Location
- Ashburn, VA
- Posts
- 47
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What would force that function to fire though? Like I have functions that fire with the onClick. But what would I use to fire whenever?
-
Jul 23, 2007, 06:55 #4
- Join Date
- Jul 2006
- Location
- Leeds, UK
- Posts
- 38
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ah sorry, you could use onblur (defocus) on the price field, but that may not be reliable enough, possibly onkeyup on the price field?
-
Jul 23, 2007, 13:44 #5
- Join Date
- Feb 2004
- Location
- Ashburn, VA
- Posts
- 47
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah ok, gotcha now. Thanks for the assist, I'll give all that a go.
Bookmarks