0% found this document useful (0 votes)
24 views

Javascript: Euis Marlina, S.Kom HP: 08179424319

This document discusses using JavaScript to make web content more dynamic and introduce interactivity. It provides examples of using JavaScript for form validation, confirmation messages, and responding to button clicks and page loads. The formatting for JavaScript code is also demonstrated, showing how to declare JavaScript within <script> tags. Key events that can be used with JavaScript like onClick, onLoad, and onMouseOver are listed.

Uploaded by

amin alsa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Javascript: Euis Marlina, S.Kom HP: 08179424319

This document discusses using JavaScript to make web content more dynamic and introduce interactivity. It provides examples of using JavaScript for form validation, confirmation messages, and responding to button clicks and page loads. The formatting for JavaScript code is also demonstrated, showing how to declare JavaScript within <script> tags. Key events that can be used with JavaScript like onClick, onLoad, and onMouseOver are listed.

Uploaded by

amin alsa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

JavaScript 

Euis Marlina, S.Kom

Email : [email protected]
http://euismarlina.edublogs.org
HP : 08179424319
Pengantar
 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 :
1. OnClick
2. OnLoad
3. OnMouseOver
4. 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>

You might also like