I have a variable in Javascript:
var test ="whatever"
I just want to pass this variable inside a hidden input:
<input type="hidden" class="myinput" value="">
I tried:
$('.myinput').attr('test');
But it does not seem to work.
Thank you for your help.
I have a variable in Javascript:
var test ="whatever"
I just want to pass this variable inside a hidden input:
<input type="hidden" class="myinput" value="">
I tried:
$('.myinput').attr('test');
But it does not seem to work.
Thank you for your help.
Share Improve this question edited Nov 12, 2012 at 22:48 Nat Ritmeyer 5,6788 gold badges48 silver badges59 bronze badges asked Nov 12, 2012 at 22:43 Juliette DupuisJuliette Dupuis 1,0372 gold badges14 silver badges22 bronze badges 1- Did it help, if so please mark it is as accepted for closure. – Selvakumar Arumugam Commented Nov 13, 2012 at 20:00
1 Answer
Reset to default 8- Use
.val
function to set the value of hidden input. - Remove the quotes to consider it as a variable and not a string literal.
See below code:
$('.myinput').val(test);