SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: IF statement?

Hybrid View

  1. #1
    SitePoint Enthusiast
    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.

  2. #2
    SitePoint Enthusiast
    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.

  3. #3
    SitePoint Enthusiast
    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?

  4. #4
    SitePoint Enthusiast
    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?

  5. #5
    SitePoint Enthusiast
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •