Reputation: 846
In a page I have a number of text box with name in array format. I want to put a value 'test' in one of them when a function is executed or event is occured. But my jquery code puts value in all the textboxes. Also I cannot put ID to the textbox as its framework generated.
<input type="text" maxlength="255" name="School[school_name]">
<input type="text" maxlength="255" name="School[contact_person]">
<input type="text" maxlength="255" name="School[test]">
$('input:text[name=School[school_name]]').val('test');
Thanks Ab
Upvotes: 0
Views: 430
Reputation: 12701
$('input[name="School[school_name]"]').val('test');
Will do the magic for you. The syntax is: $('tag[attribute="value"]')
Upvotes: 0
Reputation: 4234
Here's a jsfiddle that shows how to do it: http://jsfiddle.net/2eYwQ/11/
Put the actual name in quotes.
Upvotes: 1
Reputation: 5412
Put quotes around the name:
$('input:text[name="School[school_name]"]').val('test');
Upvotes: 1