0

I have this form which is in HTML

<form id="myform" action="handler.php">
   <input id="username" />
   <input id="password" type="password" />
   <button id="login">Login</button>
</form>

I would like to submit this form without using jquery, How do I do this?

also, I have the following code which needs to run before submit...

function validate(){
   return username.value && password.value;
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

2 Answers2

5

Replacing <button id="login">Login</button> by :

<input type="submit" value="Login" />

OR

<button type="submit">Login</button>

And adding onSubmit event in your form like :

<form id="myform" action="handler.php" onsubmit="return validate();">

be careful with your validate() function, where password and username needs to be set with var password = document.getElementById("password");

GGO
  • 2,678
  • 4
  • 20
  • 42
0

use type="submit"

eg:

<button type="submit" id="login">Login</button>

Saw Zin Min Tun
  • 642
  • 3
  • 9