Latihan Form HTML + Java Script Validasi


Kode latihan HTML + Javascript validasi
Menu input dan validasi:

  1. Form inputan harus di isi
  2. Password minimal 6 karakter
  3. input format email dan hidden password

<!DOCTYPE html>
<html>
<head>
<title>Latihan Form HTML + Js</title>

</head>
<body bgcolor="#ddd">
<form name="form"action="hasil.php" method="get"
onsubmit="return validasi()">
<table style="padding:30px;">
<tr>
<td>Nama</td><td><input type="text" name="nama"></td>
</tr>
<tr>
<td>e-mail</td><td><input type="email" name="email"></td>
</tr>
<tr>
<td>Password</td><td><input type="password" name="password"></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Daftar"></td>
</tr>
</table>
</form>

<script> 
function validasi(){ 
var nama=document.form.nama.value; 
var email=document.form.email.value; 
var password=document.form.password.value; 

if (nama==""){ 
alert("Nama harus di isi"); 
return false; 
}else if(email==""){
alert("e-mail harus di isi"); 
return false; 
}else if(password.length < 6){ 
alert("Password minimal 6 karakter"); 
return false; 
}else if(password==""){
alert("Password tidak boleh kosong"); 
return false; 
}
} </script>

</body>
</html>
READ :  Ternyata Bunga Ini Bisa Mempercantik Wajah Anda