0

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.

1
  • Did it help, if so please mark it is as accepted for closure. Commented Nov 13, 2012 at 20:00

1 Answer 1

8
  1. Use .val function to set the value of hidden input.
  2. Remove the quotes to consider it as a variable and not a string literal.

See below code:

$('.myinput').val(test);
Sign up to request clarification or add additional context in comments.

1 Comment

"Use .val function to set the value of the textbox" More to the point, to set the value of a hidden input. (Hidden inputs are not text boxes.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.