Bug Tracker

Modify

Ticket #4868 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.