/    Sign up×
Community /Pin to ProfileBookmark

Escaping "[]" characters

I have an input text array on a form which gets parsed by PHP, so they must have [] on the end. Specifically, they’re called select[]. However, I have a javascript that needs to access the 6th and 7th elements if this array. Since javascript interprets [] characters as an array, how do I force it to use “select[]” as the object? i.e.: “select[]”[6].value

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryFeb 13.2004 — Try this:

document.forms[whatever].elements['select[]'].value

Adam
Copy linkTweet thisAlerts:
@Chris-IAauthorFeb 13.2004 — Here's the exact line of code I used:

document.forms[report].elements['select[]'][6].value="STRING"

I got the error: 'document.forms[..].element' is null or not an object

I also tried this: document.forms[report].elements['select[]'[6]].value="STRING"

and came up with the same error ?

I'm assuming its not finding forms[report], am I misusing this?
Copy linkTweet thisAlerts:
@AdamGundryFeb 13.2004 — Sorry, I did not quote whatever because it could also have been a number if you were not using a named form. You need this:

document.forms['report'].elements['select[]'][6].value="STRING"

Adam
Copy linkTweet thisAlerts:
@Chris-IAauthorFeb 13.2004 — Thanks, works like a charm ?

I can't believe I missed single quotes... lol. I thought I had learned my lesson using MySQL :rolleyes:
Copy linkTweet thisAlerts:
@AdamGundryFeb 13.2004 — No problem. ?

Adam
×

Success!

Help @Chris-IA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...