0

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).

3 Answers 3

2

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

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

Comments

1

No jQuery needed

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

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

Comments

1

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
});

3 Comments

Is that just normal Javascript, or is it jQuery? I ask because I don't recognize the $ phrase. As you can probably tell, I am new to this language.
That's jQuery. Regular JS is a bit more complex here, as different browsers use different functions to bind events.
Here's how you do it without jQuery: creativemeat.com/development/…

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.