Cara membuat form seperti yang telah dijelaskan diatas, berikut adalah contoh kodenya :
<script language="javascript"> function cekkosong(form) { ////------cek kekosongan if(form.txtnama.value.length==0){ alert("Nama, harap diisi !."); form.txtnama.focus(); return false; } if(form.txtalamat.value.length==0){ alert("Alamat, harap diisi !."); form.txtalamat.focus(); return false; } ////----cek format email var reEmail=/^.+\@.+\..+$/ var defaultEmptyOK=false function isEmpty(s) { return((s==null)||(s.length==0)) } function isEmail(s) { if(isEmpty(s)) if(isEmail.arguments.length==1) return defaultEmptyOK; else return(isEmail.arguments[1]==true); else { return reEmail.test(s) } } var emaile=form.txtemail.value; if(!isEmail(emaile)) {alert("Email harus valid, contoh : idemail@namaperusahaan.xxx"); form.txtemail.focus(); return false; } } </script> <form action="" method="post" onSubmit="return cekkosong(this)"> <input name="txtnama" type="text" id="txtnama" size="40"> <input name="txtalamat" type="text" id="txtalamat" size="40"> <input name="txtemail" type="text" id="txtemail" size="40"> <input type="submit" name="tombol" value="Simpan" /> </form>
0 komentar:
Posting Komentar