jQuery: Select form fields with square brackets (such as names[]) using jQuery
Question by Guest | 2012-07-18 at 19:13
I have an HTML form including some fields named with square brackets in order to access them later better with PHP. So for example:
<input type="text" name="names[]">
Now I want to use JavaScript/jQuery to select and to change these fields. However, jQuery apparently does not like the brackets, because as soon as I leave them out, it is working.
Is there still a way to select names with square brackets using jQuery?
Related Topics
Send Form Input as an Array to PHP Script
Tip | 0 Comments
jQuery: Count characters from multiple input fields
Tip | 0 Comments
Delphi: Event Order of a Form - From OnCreate to OnDestroy
Info | 1 Comment
JavaScript: Catch Submit of Form
Tutorial | 0 Comments
MySQL: CSV Export as File stored on the Server
Tutorial | 0 Comments
jQuery: Note when leaving a website and a form has not been submitted
Tutorial | 2 Comments
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
The square brackets [ and ] have a special meaning within a selector in jQuery. Therefore, you have to escape those brackets that they are recognized as part of the name.
Here's an example:
The last bracket is the closing bracket of the first bracket. The second last bracket is part of the name of the items to be selected. So this is masked with \\ and thus evaluated as part of the name.
2012-07-19 at 22:55