Referencing array-syntax-like form variable

D

Diego Pino

Hello,

I am experience some problems reading a form variable from a
Javascript function. The point with this particular variable is that
its name has the following syntax:

<input name="tx_impexp[tt_content:159]"/>

I want to set this var to 1 from my javascript function, so I tried
to execute the following line of code:

document.frm_1.tx_impexp[exclude][tt_content:159].value=1;

Unfortunately the following error come up:

Error: missing ] in index expression
document.frm_1.tx_impexp[exclude][tt_content:159].value=1
--------------------------------------------------------------|

It seems Javascript expects to close down the bracket at the position
marked...An easy solution would be to change my var syntax but the
point is that I cannot since I am using an already made script and I
should not modify it.

Just wandering if this is due to a syntax error defined according to
Javascript specification language or there is something wrong with
this. Maybe there is a work-around to get this done. Any help would be
highly appreciated.

Thank you very much!

Diego Pino
 
T

Tom Cole

Hello,

I am experience some problems reading a form variable from a
Javascript function. The point with this particular variable is that
its name has the following syntax:

<input name="tx_impexp[tt_content:159]"/>

I want to set this var to 1 from my javascript function, so I tried
to execute the following line of code:

document.frm_1.tx_impexp[exclude][tt_content:159].value=1;

Unfortunately the following error come up:

Error: missing ] in index expression
document.frm_1.tx_impexp[exclude][tt_content:159].value=1
--------------------------------------------------------------|

It seems Javascript expects to close down the bracket at the position
marked...An easy solution would be to change my var syntax but the
point is that I cannot since I am using an already made script and I
should not modify it.

Just wandering if this is due to a syntax error defined according to
Javascript specification language or there is something wrong with
this. Maybe there is a work-around to get this done. Any help would be
highly appreciated.

Thank you very much!

Diego Pino

You can use document.getElementByName('tx_impexp[tt_content:159]')
[0].value = 1; (or maybe for your example use
document.getElementByName('tx_impexp[tt_content:159]')[exclude].value
= 1;

OR

You can provide an id attribute and find it using that (i.e. using
getElementById('value')) without interfering with the name attribute.
 
R

RobG

Hello,

I am experience some problems reading a form variable from a
Javascript function. The point with this particular variable is that
its name has the following syntax:

<input name="tx_impexp[tt_content:159]"/>

I want to set this var to 1 from my javascript function

The group FAQ is a great resource:

"4.25 My element is named myselect[] , how do I access it?"
<URL: http://www.jibbering.com/faq/#FAQ4_25 >
 
D

Diego Pino

You can use document.getElementByName('tx_impexp[tt_content:159]')
[0].value = 1; (or maybe for your example use
document.getElementByName('tx_impexp[tt_content:159]')[exclude].value
= 1;

Sorry, document.getElementsByName('tx_impexp[exclude][tt_content:
159']).value it seems to work, at least no error is raised, but what
is actually happening is that getElementsByName is returning an
undefined value.
OR

You can provide an id attribute and find it using that (i.e. using
getElementById('value')) without interfering with the name attribute.

Nice work-around!!! I did it and well, it worked!

Thanks Tom!
 
R

RobG

You can use document.getElementByName('tx_impexp[tt_content:159]')
[0].value = 1; (or maybe for your example use
document.getElementByName('tx_impexp[tt_content:159]')[exclude].value
= 1;

Sorry, document.getElementsByName('tx_impexp[exclude][tt_content:
159']).value it seems to work, at least no error is raised, but what
is actually happening is that getElementsByName is returning an
undefined value.

No, it doesn't. It returns a (possibly empty) collection.

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259 >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top