Skip to main content

Bug Tracker

Side navigation

#4868 closed bug (invalid)

Opened July 08, 2009 07:40AM UTC

Closed October 02, 2009 01:49AM UTC

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

Attachments (0)
Change History (2)

Changed July 28, 2009 10:52PM UTC by DDaviesBrackett comment:1

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()); .

Changed October 02, 2009 01:49AM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed

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