Get the value in an input text box Get the value in an input text box jquery jquery

Get the value in an input text box


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


You can only select a value with the following two ways:

// First way to get a valuevalue = $("#txt_name").val(); // Second way to get a valuevalue = $("#txt_name").attr('value');

If you want to use straight JavaScript to get the value, here is how:

document.getElementById('txt_name').value 


There is one important thing to mention:

$("#txt_name").val();

will return the current real value of a text field, for example if the user typed something there after a page load.

But:

$("#txt_name").attr('value')

will return value from DOM/HTML.