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
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using a parameter in a function

    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.

    Thanks,
    -UnSaniTiZ

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't use variables with dot syntax. You need to use array syntax instead.
    Code:
    function trackSelect(selectObject){
    var formObject = document.quoteForm[selectObject];
    }
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    works fine now thanks.


  •  

    Posting Permissions

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