I want to add some value in an input field with jQuery. The problem is with the ID of the input field. I am using the id such as options[input2]. In that case my co
options[input2]
You have to escape [ and ]. Try this:
[
]
$('.button').click(function(){ var fieldID = $(this).prev().attr("id"); fieldID = fieldID.replace(/([\[\]]+)/g, "\\$1"); $('#' + fieldID).val("hello world"); });
Demo: http://jsfiddle.net/7RJtf/1/