Hello, I have an html5 form, I want to validate it and when clicking on submit, it calls the function register.
The way i done it below is not working. Can you please help me? I think i should do it with javascript but i dont know exactly.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Required Demo</title>
</head>
<body>

    <form>
        <label>
            First Name:
            <input required title="First Name is Required!" />
        </label>
        <label>
            Last Name:
            <input required title="Last Name is Required!" />
        </label>
       <input type="submit" value="Submit" onclick= "register()"/>
    </form>

</body>
</html>

Try this instead...on the form element. Then place your javascript validation code in the validateForm function.

<form action="process.htm" onsubmit="return validateForm()" method="post">

actually i insert this ,

<form onsubmit="register()">

and it works. Can you tell me how can i validate the password field? the confirm password and password should be the same.

If all that you are concerend with is that the two password match, just inlcude a conditional statement in your code that checks if the value of the two input fields are equal.

in html5 or javascript?

can u tell me please? am still a beginner! :(

The validation is done using JavaScript. Here is an example.

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style>
</style>

</head>

<body>

<form onsubmit="return validate(this);">
  <label>Password:
    <input type="password" name="password" value="" />
  </label>
  <label>Confirm password:
    <input type="password" name="confirm-password" value="" />
  </label>
  <input type="submit" name="submit" value="submit" />
</form>

<script>
function validate(form) {
  var e = form.elements;

  if(e['password'].value != e['confirm-password'].value) {
    alert('Your passwords do not match.');
    return false;
    } else {
    alert('Passwords matched!');
    return true;
    }
}
</script>
</body>
</html>

It looks like you don't even know what HTML5 and JavaScript mean... They are two separated topics. Please read the links I provided for you for more understanding.

thanks problem solved

what is html java script

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.