View Full Version : Negating the effects of brackets in JS

03-11-2004, 03:37 PM
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

03-11-2004, 06:02 PM
I think this should do it for you:





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,

03-11-2004, 06:50 PM
Thanks, Sadiq! This seems to have worked perfectly well.

-Maduin Branford