javascript - How to Show Value Of Button In TextBox With JQuery? -


im sorry if easy question, new scripting , html , jquery. trying make when 1 button pressed show value in box. acheived earlier element id trying jquery , confused why following code wont work. help!

<html> <head>      <title>page title</title> </head>  <script>  $(document).ready(function(){         $('#button1').click(function(){               var number1 = "1";               $('#output').html(number1);     });   }); </script>  <body>  <input type="text"   id="output">  <input type="button" name="one" value = "1" id="button1">   </body> </html> 

to button value jquery use $("#button1").attr("value") or $("#button1").val()

in case set value of input text use $('#output').val($(this).attr("value"))

the final code shoul

<html> <head>      <title>page title</title> </head>  <script>  $(document).ready(function(){        $('#button1').click(function(){             $('#output').val($(this).val());         });   }); </script>  <body>  <input type="text"   id="output">  <input type="button" name="one" value = "1" id="button1">   </body> </html> 

simple jsfiddle demo


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -