Bug Tracker

Opened 14 years ago

Closed 13 years ago

#4868 closed bug (invalid)

Can't get element value by id

Reported by: kullar84 Owned by:
Priority: critical Milestone: 1.3.2
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Description

I can't get element value by id if id value contains "[number]". Lets say i have input field:

<input type="text" name="USERNAME[0]" id="USERNAME[0]" value="username" />

When I call alert($('#USERNAME[0]').val()); then it says undefined, but if I use this example:

<input type="text" name="USERNAME2" id="USERNAME2" value="username2" />

and call alert($('#USERNAME2').val()); then I get correct value.

Little example: http://office.5dvision.ee/~kullar/Testid/jQuery_Test/jquery.php

Change History (2)

comment:1 Changed 14 years ago by DDaviesBrackett

you are falling afoul of the escaping rules: jQuery interprets [] as indices, so you'll need to specify your hardcoded square brackets as \[\] to jQuery (which means you'll need to write
[
] into the string).

Try alert($('#USERNAME
[0
]').val()); .

comment:2 Changed 13 years ago by dmethvin

Resolution: invalid
Status: newclosed

Solution is provided in the comment above, and in the jQuery documentation.

Note: See TracTickets for help on using tickets.