I want to send a value to the form field with the jQuery. Here’s the basic code, it will work fine:
<input id="logo" name="logo" type="text" />
jQuery:
jQuery('#logo').val(imgurl);
However, I need to change the field ID to option[logo]. So I am trying this:
<input id="option[logo]" name="option[logo]" type="text" />
jQuery:
jQuery('#option[logo]').val(imgurl);
This does not work. How this can be fixed?
You can’t just use
[or]literally as characters in an attribute/element name in a JQuery selector because they have a special meaning. You have to escape them. Read the documentation here: http://api.jquery.com/category/selectors/This should work: