7

How can I get the value of an input element in jQuery?

3
  • 8
    Felix: "google it" is not an acceptable answer. Commented Sep 9, 2010 at 5:25
  • 1
    Mark i think Felix is not giving an answer just extending help to find solution by himself Commented Sep 9, 2010 at 5:28
  • on the other hand - good to have an answer to everything on SO :) Commented Sep 9, 2010 at 5:31

5 Answers 5

10

If this is your textbox:

<input type="text" id="mytextBox" value="" />

You will be getting it's value using the textbox's ID=mytextBox...

var value = $("#mytextBox").val()

References

Sign up to request clarification or add additional context in comments.

Comments

5
$("#elementId").val()

Comments

3

The best way is to use the val() function, as in:

$('#someInput').val();

You can also use the attr function to find the value for some fields

$('#someInput').attr('value');

1 Comment

how to set the attribute ?
3

The val function gets or sets the value of an input field.

Set the input value to "Hello world":

$('#myInput').val('Hello world');

Get the input value:

$('#myInput').val();

Comments

2

use jQuery('inputElement').val() to get the values of input(form) elements

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.