berikut adalah contoh dalam membuat form dengan menggunakan javascript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function cek(){
nama=document.getElementById('nama').value;
prodi=document.getElementById('prodi').value;
alamat=document.getElementById('alamat').value;
if(nama==''||nama==null){
document.getElementById('e_nama').innerHTML="Harus diisi";
return false;
}
if(prodi=='-'||prodi==''||prodi==null){
document.getElementById('e_prodi').innerHTML="Harus diisi";
return false;
}
if(alamat==''||alamat==null){
document.getElementById('e_alamat').innerHTML="Harus diisi";
return false;
}
if(nama!=''&& prodi!='-'&& alamat!='') {
document.getElementById('Hasil').innerHTML="Nama="+nama+"<br>Prodi="+prodi+"<br>Alamat="+alamat;
return false;
}
}
</script>
</head>
<body>
<form id="lat1" onsubmit="return cek();">
Nama <input type="text" id="nama">
<div id="e_nama"></div> <br>
Prodi <select id="prodi">
<option value="-">-Pilih Prodi-</option>
<option value="1">Sistem Informasi</option>
<option value="2">Teknik Informatika</option>
</select>
<div id="e_prodi"></div> <br>
Alamat <textarea id="alamat" cols="15" rows="5"></textarea>
<div id="e_alamat"></div> <br>
<input type="submit" value="OK">
</form>
<p id="Hasil">Silahkan diisi Form di atas</p>
</body>
</html>
hasil :
Subscribe to:
Post Comments
(
Atom
)
waduh.......kok penjelasannya susah dipahami ya gan.......tapi walaupun gitu saya coba jg kok gan
ReplyDeleteok.yang sussah di bagian mana gan?
ReplyDelete