473,396 Members | 1,891 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,396 software developers and data experts.

Using brackets but not wanting to have an array?

Hello dear Newsgroup,

my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor, I have to call these select fields like name[] and before
submitting, I have to mark every item (JavaScript as well)
But it seems, which is in some way logical to me, as if the javascript
doesn't want to process variables like name[] as it probably threads it
like an array, which it isn't (at least not in that context). Using
name\[\] won't work either.
What could work?

To give a small sneak of what I am doing, check
http://gosingen.dyndns.tv/sura/1/programm/addmovie.php but note that
there is still a lot of mess to be cleant, the programming proably
looks disgusting to you. It is :)

thanks in advance
Thorben

Dec 29 '05 #1
10 1492
Thorben Grosser wrote:
Hello dear Newsgroup,

my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor, I have to call these select fields like name[] and before
submitting, I have to mark every item (JavaScript as well)
But it seems, which is in some way logical to me, as if the javascript
doesn't want to process variables like name[] as it probably threads it
like an array, which it isn't (at least not in that context). Using
name\[\] won't work either.
What could work?


If you have form controls that you want to have names that include
square brackets, they might look something like:

<form name="blahForm" action="">
<select name="blahSelect[]">
...
Then you can access them using:

var theSelect = document.forms['blahForm'].elements['blahSelect[]'];
Read the FAQ on using square brackets:

<URL:http://www.jibbering.com/faq>
[...]
--
Rob
Dec 29 '05 #2
Thorben Grosser wrote in news:1135853254.064098.260210
@g44g2000cwa.googlegroups.com in comp.lang.javascript:
Hello dear Newsgroup,

my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor, I have to call these select fields like name[] and before
submitting, I have to mark every item (JavaScript as well)
But it seems, which is in some way logical to me, as if the javascript
doesn't want to process variables like name[] as it probably threads it
like an array, which it isn't (at least not in that context). Using
name\[\] won't work either.
What could work?

To give a small sneak of what I am doing, check
http://gosingen.dyndns.tv/sura/1/programm/addmovie.php but note that
there is still a lot of mess to be cleant, the programming proably
looks disgusting to you. It is :)


You possibly need to use strings (as aposed to identifiers) to
access you form elements:

var myelememnt = document.forms['myformname'].elements['item[]'];

The above is the most explicit way of accessig a form element, but:

var myelememnt = document.forms['myformname']['item[]'];

and

var myelememnt = document.myformname['item[]'];

should work too.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Dec 29 '05 #3
Works perfect, thanks to both of you :)

have a nice time

Thorben

Dec 29 '05 #4
VK

Thorben Grosser wrote:
Hello dear Newsgroup,

my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor, I have to call these select fields like name[] and before
submitting, I have to mark every item (JavaScript as well)
But it seems, which is in some way logical to me, as if the javascript
doesn't want to process variables like name[] as it probably threads it
like an array, which it isn't (at least not in that context). Using
name\[\] won't work either.
What could work?


Any JavaScript literal can be represented upon ECMA-262 chapters which
you should be able to spell alive, drunk or dead. At the very least
ECMA-262 : Book Of Source is the must. So in your case:
"[" is \u005B
"]" is \u005D
where both are in "Base Latin" Unicode table.

so

var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're looking for*.

Dec 29 '05 #5
VK wrote:
<snip>
Any JavaScript literal can be represented upon ECMA-262
chapters which you should be able to spell alive, drunk
or dead. At the very least ECMA-262 : Book Of Source is
the must. So in your case:
"[" is \u005B
"]" is \u005D
where both are in "Base Latin" Unicode table.

so

var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're
looking for*.


Pure bullshit!

<quote cite="ECMA 262, 3rd edition; Section 7.6">
....
A UnicodeEscapeSequence cannot be used to put a character into an
identifier that would otherwise be illegal. In other words, if a
\UnicodeEscapeSequence sequence were replaced by its
UnicodeEscapeSequence's CV, the result must still be a valid Identifier
that has the exact same sequence of characters as the original
Identifier.
....
</quote>

It would save everyone a great deal of time and trouble if you would do
something about learning javascript prior to pontificating on the
subject.

Richard.
Dec 30 '05 #6
On 2005-12-29, VK <sc**********@yahoo.com> wrote:

Thorben Grosser wrote:
Hello dear Newsgroup,

my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor, I have to call these select fields like name[] and before
submitting, I have to mark every item (JavaScript as well)
But it seems, which is in some way logical to me, as if the javascript
doesn't want to process variables like name[] as it probably threads it
like an array, which it isn't (at least not in that context). Using
name\[\] won't work either.
What could work?


Any JavaScript literal can be represented upon ECMA-262 chapters which
you should be able to spell alive, drunk or dead. At the very least
ECMA-262 : Book Of Source is the must. So in your case:
"[" is \u005B
"]" is \u005D
where both are in "Base Latin" Unicode table.

so

var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're looking for*.


if he's looking for a syntax error it is.

this\u005B"foo[]"\u005D = 'bar';

works better. but it's only another way of writing

this["foo[]"]='bar';

--

Bye.
Jasen
Dec 30 '05 #7
Jasen Betts wrote:
On 2005-12-29, VK <sc**********@yahoo.com> wrote:

<snip>
var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're looking for*.


if he's looking for a syntax error it is.

this\u005B"foo[]"\u005D = 'bar';

works better.

<snip>

But it doesn't work at all well. ECMA 262 is unclear as to how that
should be handled, but the implication of what it does have to say about
UnicodeEscapeSequences is that the above should be a syntax error, and
it is in IE and Opera. There is enough ambiguity in the specification to
allow Mozilla to treat the escape sequences as square brackets and so
operators but there are good reasons for expecting the syntax errors
reported by other browsers.

Javascript certainly cannot convert UnicodeEscapeSequences in its source
code into their corresponding CVs prior to tokenisation without
violating the specification with regard to end-of-line comments, regular
expression and string literals (i.e. for example, /u000A may not be
treated as a LineTerminator (ECMA 262, 3rd edition; Section 7.3) in an
end-of-line comment or a regular expression or string literal).

Richard.
Dec 30 '05 #8
Richard Cornford wrote:
Jasen Betts wrote:
On 2005-12-29, VK <sc**********@yahoo.com> wrote:
var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're looking for*.
if he's looking for a syntax error it is.

this\u005B"foo[]"\u005D = 'bar';

works better.


But it doesn't work at all well. ECMA 262 is unclear as to how that
should be handled,


IBTD, I think it is pretty clear about that.
but the implication of what it does have to say about
UnicodeEscapeSequences is that the above should be a syntax error,
True. The implication of

| Unicode escape sequences are [...] permitted in identifiers, where they
^^^^^^^^^^^^^^
| contribute a single character to the identifier, as computed by the CV
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| of the UnicodeEscapeSequence (see section 7.8.4). The \ preceding the
| UnicodeEscapeSequence does not contribute a character to the identifier.

is that the above should be equivalent to

this["foo[]"] = 'bar';

where the left hand side of the AssignmentExpression should be parsed as
_one identifier_, at least the leading `this[' and the trailing `]' as
two identifiers, _not_ the property accessor syntax:

The \UnicodeEscapeSequence is allowed only in Identifiers and StringLiterals
(the Unicode escape sequence in RegularExpressionLiterals is produced by
`\NonTerminator', not `\UnicodeEscapeSequence'); since this is obviously
no string literal, it must be an identifier.

But `[' and `]' are not allowed in Identifiers, not even per evaluated
\UnicodeEscapeSequence --

| A UnicodeEscapeSequence cannot be used to put a character into an
| identifier that would otherwise be illegal.

-- (or at least `Identifier StringLiteral Identifier = StringLiteral;'
cannot be produced by AssignmentExpression), so theoretically this is a
SyntaxError anyway.

However, ECMAScript allows a conforming implementation "to support program
[...] syntax not described in this specification." ISTM that this
provision resets all arguments about how a conforming implementation MUST
be, as argued here, to how it CAN be, perhaps SHOULD be.
and it is in IE and Opera. There is enough ambiguity in the specification
to allow Mozilla to treat the escape sequences as square brackets and so
operators but there are good reasons for expecting the syntax errors
reported by other browsers.
Yes, but I do not credit that to the specification's ambiguity.
Javascript certainly cannot convert UnicodeEscapeSequences in its
source code into their corresponding CVs prior to tokenisation without
violating the specification with regard to end-of-line comments, regular
expression and string literals
Yes it can :)
(i.e. for example, /u000A may not be
\u000A
treated as a LineTerminator (ECMA 262, 3rd edition; Section 7.3) in an
end-of-line comment or a regular expression or string literal).


True, there are limitations set by ECMAScript where \UnicodeEscapeSequence
may be used. However, by the Conformance section (e.g. ES3, section 2), a
conforming implementation is allowed to support even that. See above.

So the bottom line is instead that there is an ECMAScript implementation
that supports the suggested syntax for creating property access syntax:
JavaScript. However, as we know that there are also widely distributed
ECMAScript implementations that do not support it (JScript, the Opera
implementation), it is unwise to make use of it.
PointedEars
Dec 30 '05 #9
VK

VK wrote:
Any JavaScript literal can be represented upon ECMA-262 chapters which
you should be able to spell alive, drunk or dead. At the very least
ECMA-262 : Book Of Source is the must. So in your case:
"[" is \u005B
"]" is \u005D
where both are in "Base Latin" Unicode table.

so

var foo\u005B\u005D = 'bar';

is the equivalent of foo[] = 'bar' *in the way you're looking for*.


While writing that I was PUI (Programming Under Influence). Please take
it into consideration while commenting and penalising.

I guess to be a bs that an illegal literal would become legal just
because of being Unicode-encoded. From the other side a code string
foo[] = something; is not an illegal literal per se (as such) but only
within the applied execution context therefore this problem could be
solved on the execution level => so it can be solved.
Hic!

Dec 30 '05 #10
VK
Thorben Grosser wrote:
my problem seems somehow silly, but after some googeling, I don't find
a solution. The point is:
I have an multiple select field to which I add values using some
JavaScript. As I am willing to use all the values in a later PHP
processor


Overall (I'm PUI again) the hole problem is artificially intoroduced by
Zeev Suraski and Andi Gutmans by intoducing the idea of "no right
syntacs but PHP and no gods but convenience". There are not any legal
demands to ask "foo[]" to be just a set of char codes constituting the
literal. And I see no legal/reasonnable reasons to find a hack for a
OOP-compliant language to follow the PHP proprietary CGI build-up.

Dec 30 '05 #11

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
138
by: ambika | last post by:
Hello, Am not very good with pointers in C,but I have a small doubt about the way these pointers work.. We all know that in an array say x,x is gonna point to the first element in that...
7
by: techno | last post by:
Dear all, Our bitmap has some x00 values ( '\0' ) and i am storing it in char* array. the problem is that the '\0' is treated as eos character in c and it is truncating it so the characters...
13
by: Jim Carlock | last post by:
I have over a hundred pictures I would like to present. Is it practical to create and parse an array of pictures, picture paths, et al using server-side scripting to accomplish this? I...
19
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string?...
6
by: chopin | last post by:
I am working in Access 2003 in Windows XP. I am using Visual Basic for Applications, using DAO to write my modules. What I need to do is write a module that will compare each row to see if they are...
7
by: hlg | last post by:
I have a question, which must surely have occurred to many programmers since STL first appeared, and yet I have found no reference to it anywhere, suggesting the problem is insoluble. Nevertheless,...
8
by: case.learning | last post by:
Hi everyone, I'm doing a C problem checking for rudimentary syntax errors like unbalanced parentheses, brackets, and braces. I only know parentheses () or braces {}, but do not know what...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.