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
    Mar 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Negating the effects of brackets in JS

    Hola. Newcomer.

    Anyways, time to describe my problem. The page in question sends values via a simple post form to a server-side program. The form has a checkbox that I wish to add onClick things to, in order to disable certain textboxes when activated.

    The code works fine. The problem, it seems, is the value's names. All of the values have brackets in their names, you see. EX: AttributeValue[4]
    Whenever I try to use, say, document.productForm.AttributeValue[4].disabled, it seems to interpret it as something else though. I've checked to make sure that the code is working fine by removing the brackets from the code and form, and it does, so I know that the problem lies in the brackets. However, the bracketed variables are what the server-side program interpret, and therefor those values need to be filled in.

    So, either I need a way for JavaScript to disregard the brackets, or a way to have the values transfered into the bracketed values.

    Here's the code in question.

    function optionGrey() {
    document.productForm.AttributeValue[4].disabled = !document.productForm.AttributeValue[4].disabled;
    document.productForm.AttributeValue[5].disabled = !document.productForm.AttributeValue[5].disabled;
    document.productForm.AttributeValue[6].disabled = !document.productForm.AttributeValue[6].disabled;
    document.productForm.AttributeValue[7].disabled = !document.productForm.AttributeValue[7].disabled;
    document.productForm.AttributeValue[8].disabled = !document.productForm.AttributeValue[8].disabled;
    document.productForm.AttributeValue[9].disabled = !document.productForm.AttributeValue[9].disabled;
    document.productForm.AttributeValue[10].disabled = !document.productForm.AttributeValue[10].disabled;
    document.productForm.AttributeValue[11].disabled = !document.productForm.AttributeValue[11].disabled;
    document.productForm.AttributeValue[12].disabled = !document.productForm.AttributeValue[12].disabled;
    document.productForm.AttributeValue[13].disabled = !document.productForm.AttributeValue[13].disabled;
    }

    Docile enough. An example dummy page has been put up at http://www.ourestore.net/UniformsRU/landau70000.html

    -Maduin Branford

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think this should do it for you:

    Change:
    Code:
    document.productForm.AttributeValue[4].disabled
    to:
    Code:
    document.forms["productForm"].elements["AttributeValue[4]"].disabled
    And see how that works out. I'm not sure of the reasons for that, but I'm pretty sure that's the way it's supposed to look like if you want to access array elements.

    Hope that works,
    Sadiq.

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, Sadiq! This seems to have worked perfectly well.

    -Maduin Branford


  •  

    Posting Permissions

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