1

I want a simple program that shows an alert if a user updates a form and it's not more than 8 charterers long. I've tooled around trying to use the "onformchange" function and such, but I couldn't get it to work. I've heard about ajax but don't know how to integrate it into my problem. Any help would be great.

2 Answers 2

1

please,use the following guide to validate your form: W3Schools

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

2 Comments

That is not the effect I am looking for, I want it to happen before I click anything. The second the user updates the form, it is validated.
each input has some events you can bind to fire the validation function such as blur,change .
1

document.getElementById("submit").onclick = function() {
  document.getElementById("output").innerHTML = "";
  if (document.getElementById("input").value.length < 8) {
    document.getElementById("output").innerHTML = "input too short";
  }
}

document.getElementById("input").onkeydown = function() {
  document.getElementById("output").innerHTML = "";
  if (document.getElementById("input").value.length < 8) {
    document.getElementById("output").innerHTML = "input too short";
  }
}
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <input type="text" placeholder="some text" id="input">
        <input type="button" onclick="click()" value="submit" id="submit">
        <p id="output"></p>
    </body>
</html>

This will work, make sure to change the id's.

2 Comments

This does work, but it works on click I want it to happen as the user is going through the form. So if he is done the first input, and progress is to the second, he'll then realise he cant use that username. Is it even possible to do it?
Yes! It is, ill add it to the answer in a second

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.