View Full Version : using a parameter in a function

07-31-2006, 08:10 AM
Hi guys, I'm just about completely new to js, but I've had some experience with php and a few other languages.

This is really more of a syntax problem than anything else, I think. Should be simple for someone who knows what they're doing.

Anyway, here goes:

I'm trying to create a function that will disable a text field element in a form unless a specific value of a select element is chosen. The thing is, I need to write a function for this as I have a bunch of these text fields I will need disabled/enabled (based upon several different select elements).

I declare the function, and pass it a variable, selectObject

function trackSelect(selectObject){
var formObject = document.quoteForm.selectObject;
I am trying to get the selectObject variable's string value to be used after quote form.

IE, when I call the function I use: onChange="trackSelect('apparel')"

and I want formObject = document.quoteForm.apparel;

if someone could please tell me how to do this using parameters, I would be most grateful.


07-31-2006, 09:07 AM
You can't use variables with dot syntax. You need to use array syntax instead.

function trackSelect(selectObject){
var formObject = document.quoteForm[selectObject];

07-31-2006, 09:08 AM
works fine now :) thanks.