Piccolo
Piccolo

Reputation: 1666

Constantly refresh Javascript values of text fields

I'm working on an input form, and I have a Javascript function that gets all of the field values when you press a button. I am looking for a way to automatically refresh the Javascript values (so I can, for example, check if a username is too short on a registration page as they type, and also check if the username is available). Would this be possible?

To clarify, I have an HTML input field (for text), and as the user is typing a result, automatically update.

I'm also open to using PHP or jQuery if it's not possible using solely Javascript, but I'd prefer Javascript if it's possible. Also, sorry if this is a rather basic question, but I've searched and searched and can't find anything on it. I know it's possible because I've seen it on websites (in fact, even on this one, as you type a question, it updates the preview at the bottom).

Upvotes: 0

Views: 1284

Answers (3)

Vic
Vic

Reputation: 8991

No jQuery needed

<input type="text" onKeyUp="validate(this.value);">

function validate(value){
    //validate code on value
}

Upvotes: 1

Hoang Lam
Hoang Lam

Reputation: 464

You should use JQuery Validation Plugin to reduce the heavy checking. Check this one out at http://jquery.bassistance.de/validate/demo/

Upvotes: 2

petermk
petermk

Reputation: 777

You should monitor onkeyup event

<input type="text" id="test">

$('#test').on('keyup', function() { //this function is triggered every time the user releases a key while typing inside the text field above
    //do whatever you want here
});

Upvotes: 1

Related Questions