473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Referencing array-syntax-like form variable

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

Mar 26 '07 #1
5 2075
On Mar 26, 2:20 pm, "Diego Pino" <pinow...@gmail.comwrote:
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.

Mar 26 '07 #2
On Mar 27, 5:20 am, "Diego Pino" <pinow...@gmail.comwrote:
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 >
--
Rob
Mar 26 '07 #3
>
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!
Mar 26 '07 #4
On Mar 27, 6:44 am, "Diego Pino" <pinow...@gmail.comwrote:
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-HTM...ml#ID-71555259 >

--
Rob

Mar 26 '07 #5
Tom Cole said the following on 3/26/2007 3:46 PM:
On Mar 26, 2:20 pm, "Diego Pino" <pinow...@gmail.comwrote:
>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.
OR

You can use a reliable cross browser method that is mentioned in the FAQ
to answer this specific type question. Bracket Notation is your friend
when dealing with form elements.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: flipflop | last post by:
I need to create a global array whose dimensions depend on the contents of another global array populated at its initialisation. For example: int array1={3,2,1}; int array2]; //should be...
11
by: Edd | last post by:
Hello all, I've made a data structure and an associated set of functions to enable me to store a dynamically-sized array of elements of whatever data type I like. Well that's the idea anyway......
3
by: Nico Gerber | last post by:
I have an already developed C# application, that needs to pass a pointer to an array of bytes (of size 50), to another already developed C++ application hosted in a DLL. My array of bytes are...
0
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison...
6
by: Roman Mashak | last post by:
Hello, I encountered a piece of code, which I can't entirely understand. Here it is: #define TX_BUF_SIZE 1024 struct priv { ... unsigned char *tx_buf; unsigned char *tx_bufs;
4
by: DoomedLung | last post by:
Hey everyone, I'm currently reading Sitepoint's 'Javascript Anthology' and keep spotting a reference I'm not quite familiar with, such as 'document.getElementByTagName('p')'. What I want to...
0
by: Buglish | last post by:
Hi, Task : -Capture a HTML table with use of regular expression from a text string buffer(entire document). –Pass it to another function to create a multi dimension array out of it. - Pass it...
2
by: HockeyFan | last post by:
Yesterday, I posted a question dealing with an issue of trying to reference (from javascript on the client side) an item within a Repeater. My code was hard-coded to use the actual ClientId, but...
2
by: Andrus | last post by:
I need compile in-memory assembly which references to other in-memory assembly. Compiling second assembly fails with error Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,...
6
by: wangers16 | last post by:
Hi all, I have the following array with which I need to reference to the second item in every array and write it out onto the page, how can this be done? var arr = new Array(); arr =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.