...

View Full Version : JavaScript Form



pinkotoad
07-30-2002, 05:21 PM
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:


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:


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.

poccil
07-30-2002, 08:05 PM
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))

pinkotoad
07-30-2002, 10:37 PM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum