Pemograman HTML Menggunkan Java Script

Pemakaian Alert Pada Java Script

<HTML>
<HEAD>
<TITLE>Alert Box</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = “JavaScript”>
<!–
window.alert(“Ini merupakan pesan untuk Anda”);
//–>
</SCRIPT>
</BODY>
</HTML>

Pemakaian Metoda

<HTML>
<HEAD>
<TITLE>Skrip JavaScript</TITLE>
</HEAD>
<BODY>
Percobaan memakai JavaScript:<BR>
<SCRIPT LANGUAGE = “JavaScript”>
<!–
document.write(“Selamat Mencoba JavaScript<BR>”);
document.write(“Semoga sukses!”);
//–>
</SCRIPT>
</BODY>
</HTML>

Pemasukan Data

<HTML>
<HEAD>
<TITLE>Pemasukan Data</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = “JavaScript”>
<!–
var nama = prompt(“Siapa nama Anda?”,”Masukkan nama anda”);
document.write(“Hai, ” + nama);
//–>
</SCRIPT>
</BODY>
</HTML>

Penggunaan Fungsi

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<SCRIPT language=”Javascript”>
function pesan(){
alert (“Apa Maumu, Katakan apa Yang kau Inginkan”)
}
</SCRIPT>
<BODY onload=pesan()>
</BODY>
</HTML>


Operasi Aritmatika

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<SCRIPT language=”Javascript”>
function test (val1,val2)
{
document.write(“<br>”+”Perkalian : val1*val2 “+”<br>”)
document.write(val1*val2)
document.write(“<br>”+”Pembagian : val1/val2 “+”<br>”)
document.write(val1/val2)
document.write(“<br>”+”Penjumlahan : val1+val2 “+”<br>”)
document.write(val1+val2)
document.write(“<br>”+”Pengurangan : val1-val2 “+”<br>”)
document.write(val1-val2)
document.write(“<br>”+”Modulus : val1%val2 “+”<br>”)
document.write(val1%val2)
}
</SCRIPT>
<BODY>
<input type=”button” name=”button1″ value=”arithmetic”
onclick=test(9,4)>
</BODY>
</HTML>


Operasi Relational

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<SCRIPT language=”Javascript”>
function test () {
val1=window.prompt(“Nilai I :”)
val2=window.prompt(“Nilai II :”)
document.write(“<br>”+”val1==val2″+”<br>”)
document.write(val1==val2)
document.write(“<br>”+”val1!=val2″+”<br>”)
document.write(val1!=val2)
document.write(“<br>”+”val1&gtval2″+”<br>”)
document.write(val1>val2)
document.write(“<br>”+”val1&ltval2″+”<br>”)
document.write(val1<val2) }
</SCRIPT>
<BODY>
<input type=”button” name=”button1″ value=”relational”
onclick=test()>
</BODY>
</HTML>


Seleksi Kondisi

<HTML>
<HEAD>
<TITLE>Contoh if-else</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = “JavaScript”>
<!–
var nilai = prompt(“Nilai (0-100): “, 0);
var hasil = “”;
if (nilai >= 60)
hasil = “Lulus”;
else
hasil = “Tidak Lulus”;
document.write(“Hasil: ” + hasil);
//–>
</SCRIPT>
</BODY>
</HTML>

Operator Switch

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<SCRIPT language=”Javascript”>
function test ()
{
val1=window.prompt(“Input Nilai (1-5):”)
switch (val1)
{
case “1” :
document.write(“bilangan satu”)
break
case “2” :
document.write(“bilangan dua”)
break
case “3” :
document.write(“bilangan tiga”)
break
case “4” :
document.write(“bilangan empat”)
break
case “5” :
document.write(“bilangan lima”)
break
default :
document.write(“bilangan lainnya”)
}
}
</SCRIPT>
<BODY>
<input type=”button” name=”button1″ value=”switch”
onclick=test()>
</BODY>
</HTML>


Looping

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<BODY>
<SCRIPT language=”Javascript”>
<!–
for (x=0;x<=10;x++)
document.write(x+”<br>”)
// –>
</SCRIPT>
</BODY>
</HTML>

Looping Do While

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<BODY>
<SCRIPT language=”Javascript”>
<!–
var x=0
do{
document.write(x+”<br>”)
x++;
}
while (x<=20)
// –>
</SCRIPT>
</BODY>
</HTML>

Looping While

<HTML>
<HEAD>
<TITLE>Contoh Program Javascript</TITLE>
</HEAD>
<BODY>
<SCRIPT language=”Javascript”>
<!–
var x=0
while (x<=10){
document.write(x+”<br>”)
x++;
}
// –>
</SCRIPT>
</BODY>
</HTML>

Form Input

<html>
<head> </head>
<SCRIPT language=”Javascript”>
function test () {
var val1=document.kirim.T1.value
if (val1%2==0)
document.kirim.T2.value=”bilangan genap”
else
document.kirim.T2.value=”bilangan ganjil”
}
</SCRIPT>
<body>
<form method=”POST” name=”kirim”>
<p>BIL <input type=”text” name=”T1″ size=”20″>
MERUPAKAN BIL <input type=”text” name=”T2″ size=”20″>
</p>
<p><input type=”button” value=”TEBAK” name=”B1″ onclick=test()>
</p>
</form>
</body>
</html>

Form Button

<HTML>
<HEAD>
<TITLE>Objek document</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = “JavaScript”>
<!–
function ubahWarnaLB(warna) {
document.bgColor = warna;
}
function ubahWarnaLD(warna) {
document.fgColor = warna;
}
//–>
</SCRIPT>
<H1>TES</H1>
<FORM>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Hijau”
onClick = “ubahWarnaLB(‘GREEN’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Biru”
onClick = “ubahWarnaLB(‘Blue’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Hitam”
onClick = “ubahWarnaLB(‘BLACK’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Kuning”
onClick = “ubahWarnaLB(‘YELLOW’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Coklat”
onClick = “ubahWarnaLB(‘BROWN’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Silver”
onClick = “ubahWarnaLB(‘SILVER’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Merah”
onClick = “ubahWarnaLB(‘RED’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Latar Belakang Putih”
onClick = “ubahWarnaLB(‘WHITE’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Teks Kuning”
onClick = “ubahWarnaLD(‘YELLOW’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Teks Biru”
onClick = “ubahWarnaLD(‘BLUE’)”>
<INPUT TYPE = “BUTTON”
VALUE = “Teks Hitam”
onClick = “ubahWarnaLD(‘BLACK’)”>
</FORM>

<SCRIPT LANGUAGE = “JavaScript”>
<!–
document.write(“Dimodifikasi terakhir pada ” +
document.lastModified);
//–>
</SCRIPT>
</BODY>
</HTML>

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: