SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Don't know how...

    I'm trying to figure this out... I have 3 fields to insert numbers into with predefined values. For each field I have an outcome field, so if a user inserts a number in field1, lets say 5 and the predifined number for that field is 5, the outcomefield displays "2". That part I can figure out like this:

    Code JavaScript:
    if (f1 == 5) {
         document.form1.p1.value = "2"
    }
    Now the tricky part is, that I want to be able to ad a variable number depending on a insert from the user to the default number. Lets say that the default number for all 3 fields are 5 ( It could be different for each ) and the user types in 4 in the variable field, then 4 divided would be 1.333 and that is no good. I want it to add 1 to two fields and 2 to the last field, so the default values for each field would be (6, 6, 7)... Can this be done?!?

    This is what I have tryid, but gives the number 1.333:

    Code JavaScript:
    var v1 = validNum(document.form1.variable_number.value)
    var v1b = v1 / 3
     
    if (f1 == 5 + v1b) {
         document.form1.p1.value = "2"
    }
    Hope this is understandable...

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hope this is understandable...
    Sorry, no! I'm very confused by it all. I don't see what the purpose of the user typing things in is, if they're already predefined.

    Perhaps you want the ceil or floor functions?

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason for this is Golf. If a player is playing a par4 hole then the predifined number wuld be "4". But then the player types in hes or hers handicap, and that might give the player one or more extra strokes on the hole. So if a player play a par 72 course but due to the handicap, lets say handicap 21, he is allowed to use 21 extra strokes to achive hes round. These 21 xtra strokes used by one xtra stroke pr. hole and then 2 xtra strokes on the 3 most difficult holes... This is the reason for this question... Hope this claryfies some...!

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Can you please present us with the HTML form that is to be used for this particular scenario.

    Off Topic:

    Don't get knocked unconscious and break ribs in a motorcycle accident. It f***ing hurts
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •