Reputation: 261
I want to take the value of a jquery variable and add it to the value property of an input field. I thought you can use jquery variables with HTML by doing "+VARIABLE+"...but its not working. The variable name just appears and not the value.
Here is the jQuery :
var content_unique_id = $(this).closest('.content_unique_id').val();
$('<input type="hidden" name="content_unique_id[]" value="+content_unique_id+" />').insertAfter('.content_container:last');
Upvotes: 0
Views: 103
Reputation: 298246
Here's another way of doing it:
$('<input>', {
type: 'hidden',
name: 'content_unique_id[]',
value: content_unique_id
}).insertAfter('.content_container:last');
Upvotes: 2
Reputation: 191749
You need to break out of the string so the value is interpolated:
$('<input type="hidden" name="content_unique_id[]" value="'
+ content_unique_id + '" />')
Alternatively you could use $("<input...>").val(content_unique_id)
Upvotes: 2
Reputation: 494
value="' + content_unique_id + '"
add single quotes before and after +
plus signs
Upvotes: 2