Take the 2-minute tour ×

Which are the ways to get and render an input value using jQuery?

Here is one:

<script type="text/javascript">


<input type="text" id="txt_name"  />
share|improve this question
use this code: var value=$('#txt_Name').val(); You can also set the value using jquery. please look at this post at: coding-issues.blogspot.in/2013/10/… –  Ranadheer Oct 31 '13 at 9:59
add comment

5 Answers

up vote 166 down vote accepted
var bla = $('#txt_name').val();
share|improve this answer
Funny that this is suddenly an accepted answer while less concrete than mine. –  RJD22 Apr 10 '13 at 8:26
@RJD22 A buddy of OP's, perhaps? –  Adrian Carneiro Apr 10 '13 at 22:41
@RJD22 you over explained –  Asher Aug 21 '13 at 9:37
@Asher My answer has been updated to suit the needs of multiple options. Also the above question does not answer the real question. The OP asked a "different" way of getting a value. So other than .val() –  RJD22 Aug 21 '13 at 11:13
+1....Here made century –  VarunAgw Nov 16 '13 at 14:28
show 1 more comment

As far as I know you can only select a value with these 2:

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


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

if you want to use normal javascript (I think it's less elegant):


Then you can alert the value by doing:


Or you could print it into your HTML/DOM:



share|improve this answer
This what i expected... –  Bharanikumar Nov 3 '10 at 15:16
good to know. Please select this answer as correct answer :). I like the kudos –  RJD22 Nov 3 '10 at 15:20
I know this is an older question, but don't forget that the attr may also be replaced with prop. This is semantically better. –  Sable Foste Nov 4 '12 at 7:02
Only $("#txt_name").val(str); worked for me in Chrome to set the value. Try this post. –  gkiko Feb 5 '13 at 21:17
The jQuery append function seems to have no problem adding to the HTML while keeping form values. –  Adam F Jun 7 '13 at 19:30
show 2 more comments

You can get the value attribute directly since you know it's an <input> element, but your current usage of .val() is already the current one.

For the above, just use .value on the DOM element directly, like this:

share|improve this answer
other then this val() –  Bharanikumar Nov 3 '10 at 15:09
@Bharan Why do you need an alternative? –  Pete Herbert Penito Nov 3 '10 at 15:14
in some place, i would like to use alternative, –  Bharanikumar Nov 3 '10 at 16:09
add comment

I think this function is missed here in previous answers

.val( function(index, value) ) 
share|improve this answer
add comment

You can get value like this:

share|improve this answer
add comment

Your Answer


