tags:

views:

25

answers:

2

Hi, I am new to Jquery

A form with this hidden field is loaded

<input type = "hidden" class = "counter" value="6">

I use Jquery to do this

var counter = $(".counter:last").val()

then a click event adds a row with this text field

.append($('<input>').attr('type', 'text').attr('name', 'drugName["+counter+"]')

this returns

 <input size="40" type="text" name="drugName["+counter+"]">

Where am I going wrong. I tried multiple variations.

Any help/references?

A: 

What about:

.append($('<input>').attr('type', 'text').attr('name', 'drugName['+counter+']')
RC
This worked. Thanks.
RisingSun
Returns drugName[6]
RisingSun
A: 

counter is just part of a string in line:

.append($('<input>').attr('type', 'text').attr('name', 'drugName["+counter+"]')

It should have been:

.append($('<input>').attr('type', 'text').attr('name', 'drugName[' + counter + ']')
Alan Haggai Alavi
This returns drugName["6"]
RisingSun
Edited to remove double quotes.
Alan Haggai Alavi