• support@answerspoint.com

Get the value in an input text box

2321

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


0

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

0
//Get
var bla = $('#txt_name').val();

//Set
$('#txt_name').val('bla');

 

  • answered 8 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 8 years ago
  • viewed 2321 times
  • active 8 years ago

Best Rated Questions