WHAT'S NEW?
Loading...

Required Field Warning [JavaScript]

Berikut ini adalah script yang digunakan untuk menampilkan peringatan ketika user tidak memasukkan input pada field yang ditentukan dalam sebuah form html.


<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Wayne Nolting (w.nolting@home.com) -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.textfield1.value=="") {
themessage = themessage + " -
textfield1";
}
if (document.form.
textfield2.value=="") {
themessage = themessage + " -
textfield2";
}
if (document.form.
textfield3.value=="") {
themessage = themessage + " -
textfield3";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
</script>


Fungsi verify()diberikan pada event "onClick" tombol submit.
Semoga bermanfaat.

0 komentar:

Posting Komentar