-3

I have this:

$(document).ready(function() {
    $("#center").click(function{ });
}

I know that you can get documentbyID with javascript. How do I get the value of a form input with jquery?

AmitG
  • 10,365
  • 5
  • 31
  • 52
  • possible duplicate of [Jquery get form field value](http://stackoverflow.com/questions/11654449/jquery-get-form-field-value) – Dexygen Mar 30 '15 at 18:15

2 Answers2

0

To get value of a form input , use

$("#idOfInput").val();
$(".classOfInput").val();
$("[name='yourInputName']").val();

HTML

<form>
    <input type="text" name="yourInputName" class="classOfInput" id="idOfInput"/>
</form>
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
-1

Assuming you want to alert the value and you are using jquery:

function foo(){
    alert($("#myInput").val());
}

And your html:

<form>
    <input type="text" name="myInput" id="myInput"/>
</form>
<button onclick="foo()">Click</button>

Here is a fiddle as an example:

https://jsfiddle.net/6tge2fx4/

Morne
  • 1,623
  • 2
  • 18
  • 33