To get the textbox value, you can use the jQuery val() function.

For example,

  1. $(‘input:textbox’).val() – Get textbox value.
  2. $(‘input:textbox’).val(“new text message”) – Set the textbox value.

Textbox example

<html>
<head>
<title>jQuery get textbox value example</title>
 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
 
</head>
 
<body>
 
<h1>jQuery get textbox value example</h1>
 
<h4>TextBox value : <label id="msg"></label></h4>
 
<div style="padding:16px;">
	TextBox : <input type="textbox" value="Type something"></input>
</div>
 
<button id="Get">Get TextBox Value</button> 
<button id="Set">Set To "ABC"</button> 
<button id="Reset">Reset It</button>
 
<script type="text/javascript">
    $("button:#Get").click(function () {
 
	$('#msg').html($('input:textbox').val());
 
    });
 
    $("button:#Reset").click(function () {
 
	$('#msg').html("");
	$('input:textbox').val("");
 
    });
 
    $("button:#Set").click(function () {
 
	$('input:textbox').val("ABC");
	$('#msg').html($('input:textbox').val());
 
    });
 
</script>
 
</body>
</html>
Tags :
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider making a donation to the charity, thanks.

Related Posts

Popular Posts