Grady D
Grady D

Reputation: 2019

grab user inputted text from input

I have an <input Id="inputTest"> and I have tried grabbing the value, $('#inputTest').val(); but the problem is when a user types text it does not hold it in the value until the form is submitted.

How can I capture what the user types in before submitting the form?

Upvotes: 0

Views: 52

Answers (2)

Tasos
Tasos

Reputation: 5361

I was working on the Demo when a correct answer Popped up :)) anyway Lets not get it to waste. Yes thats correct. (keyup)

Demo

http://jsfiddle.net/637oaex3/

$(document).on("keyup", "#input", function(event){
var txt = $(this).val();
$("#text").html(txt);
});

Upvotes: 2

Jay Blanchard
Jay Blanchard

Reputation: 34416

You can us keyup() to get the value as it is entered -

$('input[name="foo"]').keyup(function() {
    $('#foo_result').html( $(this).val() );
});

http://jsfiddle.net/uxs14yc9/

Upvotes: 1

Related Questions