0

I have this function, that takes the value of "count", prints it and save it in a variable

<input type="number" id="count" min="1" value="1" style="text-align:center"><br><br>
        <script>

            $('#count').bind('click keyup', function(){
               alert($(this).val());
               $hello = $(this).val();
            });
        </script>

and i want to take $hello and put it in a value in a input tag, something like this

<input name="x" type="hidden" value="//here would be $hello">

How can I do that?

Thanks.

4 Answers 4

4

Try this,it will work

 $('#count').bind('click keyup', function(){
                   alert($(this).val());
                   var hello = $(this).val();
                   $("#check").val(hello);   
                });

    <input name="x" id="check" type="hidden" value="//here would be hello">
Sign up to request clarification or add additional context in comments.

1 Comment

@Hook thank u..accept the answer it will be useful for others
2

jQuery's .val() method is both a getter and a setter.

Try this:

$('input[name="x"]').val($hello);

Comments

1

User setter variable after $hello

     <input type="number" id="count" min="1" value="1" style="text-align:center"><br><br>
            <script>

                $('#count').bind('click keyup', function(){
                   alert($(this).val());
                   $hello = $(this).val();
$("#x").val($hello);
                });
            </script>

Comments

0

jQuery val() method is used to apply the value to input element:

<input type="number" id="count" min="1" value="1" style="text-align:center"><br><br>
<input name="x" type="hidden" value="//here would be $hello">
        <script>

            $('#count').bind('click keyup', function(){
               alert($(this).val());
               $hello = $(this).val();
               $('input[name="x"]').val($hello);

            });
        </script>

demo link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.