Jquery Set Value Of Textbox.

Jquery Set Value Of Textbox.

Jquery set value of Textbox.

You want to set value of text box using JQuery. Let’s see how to get html input element by ID and assign value to it.

var inputValue =   "This is value in textbox.";
   
           $("#Text1").val( inputValue  );
   

First we need to get element by ID and call val function of Jquery. Pass the expected value to val function.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript" language="javascript">
   

$(document).ready( function (){ 

    $("#Button1").click( function(){
      
    
       var inputValue =   "This is value in textbox.";

        $("#Text1").val( inputValue  );

     });
                    
 });

</script

Put above script in header of your page.

The html content.

<div>
           <input id="Text1" type="text" />
           <input id="Button1" type="button" value="button" />
       </div>

The code uses Jquery script hosted by Google CDN. To find html text box input element, we are using below syntax.

$("#Text1")

Similar syntax is used for getting html button element and attach click event to it.

Tags:

Jquery Set Value Of Textbox.Jquery Dropdown Selected ValueJQuery Hidden Field Set ValueJQuery TextBox Value()JQuery access label control and set valueGet Selected Value From Dropdownlist [JQuery]Learning JqueryHow to get Jquery selected optionJQuery get Value Of TextareaBasics of jqueryJQuery set .focus()

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.