Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: JavaScript Form

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Detroit MI
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript Form

    Hi, I'm trying to make a script that will take the index of a drop down box and subtract it from the selectedIndex. This is how I am trying to do it:
    Code:
    var Xvalue = new Array(6)
    Xvalue[0] = 75
    Xvalue[1] = 100
    Xvalue[2] = 120
    Xvalue[3] = 140
    Xvalue[4] = 180
    Xvalue[5] = 215
    
    var X = Xvalue[form.X.selectedIndex]
    
    function AddTotal() {
    Xadd = (Xvalue[form.X.Index]) - X)
    }
    Then I use this to write it to the document:
    Code:
    document.write(AddTotal(CPUadd))
    The problems I am having are:
    1. It keeps telling me that ";" was expected in strange places, where I haven't even touched since I tried implement this.
    2. 'CPUadd' is undefined.
    3. It tells me that there was an object expected in the <BODY> tag.

  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var Xvalue = new Array(6)
    Xvalue[0] = 75
    Xvalue[1] = 100
    Xvalue[2] = 120
    Xvalue[3] = 140
    Xvalue[4] = 180
    Xvalue[5] = 215
    
    // form is not defined
    var X = Xvalue[form.X.selectedIndex]
    
    // Since it is unclear whether CPUadd should be an array or a number,
    // I assume the first parameter is an array.
    function AddTotal(val) {
    // This line, the way you wrote it, causes a syntax error, since there were more closing than 
    // opening parentheses.
    return (val[form.X.Index]) - X
    }
    
    var CPUadd=0;
    // CPUadd must be declared in advance.  There must be at least one parameter to 
    // the AddTotal function. 
    document.write(AddTotal(CPUadd))
    Last edited by poccil; 07-30-2002 at 09:07 PM.

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Detroit MI
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry, a couple of brain farts there.
    I meant:

    document.write(AddTotal(Xadd))

    And the extra ')' was just a typo when transfering it over to here.

    And the name of the form is: form

    I am extremely uncreative at times...
    Last edited by pinkotoad; 07-31-2002 at 07:22 AM.


  •  

    Posting Permissions

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