Small JS tweeking - please help.

Discussion in 'JavaScript' started by Talker, Mar 5, 2008.

  1. #1
    Hi,

    I have a small function which is giving an error on page load and when the function is fired. The code is:

    
    function cost(stitchout) {
    
        if(stitchout == "1" && form1.eststitches.value>5000)
        {
            form1.estcost.value = CurrencyFormatted(((form1.eststitches.value/1000)*0.25) + 0.50);
        }
        else if(stitchout == "1" && form1.eststitches.value<=5000)
            form1.estcost.value = 1.75;
        }
        else if(stitchout == "0" && form1.eststitches.value>5000)
        {
            form1.estcost.value = CurrencyFormatted(((form1.eststitches.value/1000)*0.5) + 0.50);
        }
        else if(stitchout == "0" && form1.eststitches.value<=5000){
            form1.estcost.value = 3.00;
        }
        
    }
    
    Code (markup):
    The error i get on page load is:
    Line: 19, character: 2, Error: Syntax Error
    In the Above code, first line is 13 and last line is 30.

    The error i get on "Onblur" Even (when function is called):
    Line: 343, character: 1, Error: Object Expected
    Line 343 is a simple <td> block with a Div align right tag. It has nothing to do with the JS.


    Kindly help me solve this error.
    Regards
    Talker.
     
    Talker, Mar 5, 2008 IP
  2. in2clearsky

    in2clearsky Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hey, got your pm and i'm here :)

    For the first error you miss blanket { on line 19.

    
    else if(stitchout == "1" && form1.eststitches.value<=5000) [COLOR="Red"]{[/COLOR]
            form1.estcost.value = 1.75;
        }
    
    
    Code (markup):
    For second error, it might cause from the first error. When you try to call function but the function contains error so it throw another error.

    PM. me if you still encounter problem ;)
     
    in2clearsky, Mar 5, 2008 IP
    Talker likes this.
  3. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #3

    Wowowow !!
    You cought it m8, thanks for the help. Adding the { fixed my JS.

    rep given to you for your help !

    Talker.
     
    Talker, Mar 5, 2008 IP