JavaScript

Euis Marlina, S.Kom Email : euismarlina@gmail.com http://euismarlina.edublogs.org HP : 08179424319

Pengantar

 

5. 6. 7. 8.

Dengan JavaScript, maka konten website menjadi lebih dinamis. JavaScript memungkinkan adanya event-event tertentu pada setiap komponen form. JavaScript digunakan untuk membuat pesan warning. Gunakan beberapa event ONxxx pada atribut komponen, misalnya : OnClick OnLoad OnMouseOver OnFocus, dll

Format Kode JavaScript

<SCRIPT LANGUAGE="text/javascript"> <!– deklarasi kode javascript --> </SCRIPT>

Contoh
<html> <head> <title>Untitled Document</title> </head> <script language="javascript"> function dontClick() { alert("I told you don't click me !"); } </script> <body> <form name="form1"> <input type="button" name="button" value="Don't click me" onClick="dontClick()"> </form> </body> </html>

Pesan Konfirmasi
                     

<html> <head> <title>Untitled Document</title> </head> <script language="javascript"> function konfirmasi() { if(confirm("Yakin Mau Keluar Windows ?")) { alert("Anda mengklik tombol [OK]"); } else { alert("Anda mengklik tombol [CANCEL]"); } } </script> <body> <form name="form1" method="post" action=""> <input type="button" name="button" value="Konfirmasi“ onClick="konfirmasi()"> </form> </body> </html>

Validasi Form
<html> <head> </head> <script language="javascript"> function Empty(field) { if(field == "") { return(true); } else { return(false); } }

function Validate(form) { var error = 0; if(Empty(form.term.value)) error = 1; if(error) { alert("Error, karena anda belum menginputkan teks !"); } else { form.submit(); } } </script>

<body> <form name="form1" method="post"> <input name="term" size=15 maxlength=50> <input type="button" value="Search" onClick="Validate(this.form);"> </form> </body> </html>

Sign up to vote on this title
UsefulNot useful