I have this code. I'd like to output input value but it appears as "$(this).val()" in html.
bulkEdit.append('<input type="hidden" name="Post[id][]" value="$(this).val()" /> ');
How should I change this code in order to output the value selected jquery object has?
Thanks,
I have this code. I'd like to output input value but it appears as "$(this).val()" in html.
bulkEdit.append('<input type="hidden" name="Post[id][]" value="$(this).val()" /> ');
How should I change this code in order to output the value selected jquery object has?
Thanks,
Share Improve this question asked Aug 28, 2013 at 23:54 HayatoHayato 5611 gold badge10 silver badges15 bronze badges6 Answers
Reset to default 3Anything within the double quotes will be outputted as text. To output the javascript result, you need to use concatenation.
bulkEdit.append('<input type="hidden" name="Post[id][]" value="'+$(this).val()+'" /> ');
Use Concatenation. and do move it outside double quotes. Else it will be just as text NOT javascript
It will do the job :
bulkEdit.append('<input type="hidden" name="Post[id][]" value="'+$(this).val()+'" /> ');
:)
Use string concatenation?
bulkEdit.append('<input type="hidden" name="Post[id][]" value="' + $(this).val() + '" /> ');
You seem to be looking for
bulkEdit.append('<input type="hidden" name="Post[id][]" value="'+$(this).val()+'" /> ');
With the exception of events (OnClick, OnMouseOver, etc), the contents of an attribute are interpreted as just text--not Javascript. In order to have the value
of your hidden input field contain $(this).val()
, you'll need to concatenate the javascript with the HTML. This means you're looking for:
bulkEdit.append('<input type="hidden" name="Post[id][]" value="' + $(this).val() + '" /> ');
You can Use String Concatenation to output your Value,
bulkEdit.append('<input type="hidden" name="Post[id][]" value="' + $(this).val() + '" /> ');
More about String Concatenation: http://www.quirksmode/js/strings.html#conc