Get the value in an input text box
What are the ways to get and render an input value using jQuery?
My Code is:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
$("#txt_name").keyup(function(){
alert($(this).val());
});
})
</script>
<input type="text" id="txt_name" />
2Answer
You can only select a value with the following two ways:
// First way to get a value
value = $("#txt_name").val();
// Second way to get a value
value = $("#txt_name").attr('value');
If you want to use straight JavaScript to get the value, here is how:
document.getElementById('txt_name').value
- answered 8 years ago
- Community wiki
//Get
var bla = $('#txt_name').val();
//Set
$('#txt_name').val('bla');
- answered 8 years ago
- Community wiki
Your Answer