Validasi Form Dengan Javascript
<script type="text/javascript">
//Ini adalah fungsi untuk falidasi form
function validasi_input(form){
if (form.nobp.value == ""){
alert("Nobp masih kosong!");
form.nobp.focus();
return (false);
}
if (form.nobp.value == ""){
alert("Nobp masih kosong!");
form.nobp.focus();
return (false);
}
if (form.nama.value == ""){
alert("Nama masih kosong!");
form.nama.focus();
return (false);
}
if (form.alamat.value == ""){
alert("Alamat masih kosong!");
form.alamat.focus();
return (false);
}
alert("Data Langkap");
return (true);
}
alert("Nama masih kosong!");
form.nama.focus();
return (false);
}
if (form.alamat.value == ""){
alert("Alamat masih kosong!");
form.alamat.focus();
return (false);
}
alert("Data Langkap");
return (true);
}
</script>
<form name="form1" method="post" action="simpan.php" onsubmit="return validasi_input(this)">
<table width="326" border="1" align="center">
<tr>
<td colspan="3"><center>FORM ENTRY</center></td>
</tr>
<tr>
<td width="132" >Nobp</td>
<td width="21" >:</td>
<td width="151" ><label for="textfield"></label>
<input type="text" name="nobp" id="nobp" size="9" nextlengt="11"/></td>
</tr>
<tr>
<td >Nama</td>
<td >:</td>
<td ><label for="textfield2"></label>
<input type="text" name="nama" id="nama"></td>
</tr>
<tr>
<td >Alamat</td>
<td >:</td>
<td ><label for="textfield3"></label>
<input type="text" name="alamat" id="alamat"></td>
</tr>
<tr>
<td >Jenis Kelamin</td>
<td >:</td>
<td ><label for="jk"></label>
<label for="select"></label>
<select name="jk" id="select">
<option>laki-laki</option>
<option>Perempuan</option>
</select></td>
</tr>
<tr>
<td colspan="3"> <input type="submit" name="button" id="button" value="Simpan" />
<input type="submit" name="button2" id="button2" value="Submit" />
</tr>
</table>
</form>
<table width="326" border="1" align="center">
<tr>
<td colspan="3"><center>FORM ENTRY</center></td>
</tr>
<tr>
<td width="132" >Nobp</td>
<td width="21" >:</td>
<td width="151" ><label for="textfield"></label>
<input type="text" name="nobp" id="nobp" size="9" nextlengt="11"/></td>
</tr>
<tr>
<td >Nama</td>
<td >:</td>
<td ><label for="textfield2"></label>
<input type="text" name="nama" id="nama"></td>
</tr>
<tr>
<td >Alamat</td>
<td >:</td>
<td ><label for="textfield3"></label>
<input type="text" name="alamat" id="alamat"></td>
</tr>
<tr>
<td >Jenis Kelamin</td>
<td >:</td>
<td ><label for="jk"></label>
<label for="select"></label>
<select name="jk" id="select">
<option>laki-laki</option>
<option>Perempuan</option>
</select></td>
</tr>
<tr>
<td colspan="3"> <input type="submit" name="button" id="button" value="Simpan" />
<input type="submit" name="button2" id="button2" value="Submit" />
</tr>
</table>
</form>
ConversionConversion EmoticonEmoticon