Dinda Ayu Subagio's Blog

Selamat Datang :)

Client Side Programming (Javascript)

Posted Selasa, 24 Mei 2011 by bahagia bersama dinda :)


Objektif
¡  Scripting Variable
¡  Scripting Arithmetic
¡  Scripting Comparison
¡  Scripting Branching
¡  Scripting PopUp
¡  Scripting Function
¡  Scripting Loops
¡  Scripting Event
¡  Scripting Error Handling
¡  Scripting Special Characters

What is Javascript
JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari.
•          JavaScript was designed to add interactivity to HTML pages
•          JavaScript is a scripting language
•          A scripting language is a lightweight programming language
•          JavaScript is usually embedded directly into HTML pages
•          JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
•          Everyone can use JavaScript without purchasing a license

Scripting Variable
Rules for JavaScript variable names:
•          Variable names are case sensitive (y and Y are two different variables)
•          Variable names must begin with a letter or the underscore character
Note: Because JavaScript is case-sensitive, variable names are case-sensitive.
Examples declaring variable in Javascript :
<html>
                <body>
                                <script type="text/javascript">
                                <!--
                                var a = "Kelas Desain dan Pemrograman Web";
                                //-->
                                </script>
                </body>
</html>
Beberapa variable in javascipt;
Var a = “teguh”;  ->(string)
Var b = 123;       ->(numerik)
Var c = 123.321; ->(float)
Convert nilai:
Var d = parseInt(123.321);
Var e = parseFloat(123.01);

Scritping Arithmetic
Arithmetic operators are used to perform arithmetic between variables and/or values.
Given that y=5, the table below explains the arithmetic operators: 

Operator
Decription
Examples
Result
+
Addition
x=y+2
X=7
-
Subtraction
x=y-2
X=3
*
Multiplication
x=y*2
X=10
/
Division
x=y/2
X=2.5
%
Modulus (division remainder)
x=y%2
X=1
++
Increment
x=++y
X=6
--
Decrement
x=--y
X=4


Scripting Comparison
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Given that x=5, the table below explains the comparison operators:

Operator
Description
Example
==
Is equal to
x==8 is false
===
is exactly equal to (value and type)
x===5 is true
x==="5" is false
!=
is not equal
x!=8 is true
> 
is greater than
x>8 is false
< 
is less than
x<8 is true
>=
is greater than or equal to
x>=8 is false
<=
is less than or equal to
x<=8 is true

Logical Operator :
Logical operators are used to determine the logic between variables or values.
Given that x=6 and y=3, the table below explains the logical operators: 

Operator
Description
Example
&&
and
(x < 10 && y > 1) is true
||
or
(x==5 || y==5) is false
!
not
!(x==y) is true

Scripting Branching
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
if statement - use this statement to execute some code only if a specified condition is true
if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false
if...else if....else statement - use this statement to select one of many blocks of code to be executed
switch statement - use this statement to select one of many blocks of code to be executed 

Scripting PopUp
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box. 

Alert Box
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed. 

Confirm Box
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.

Prompt Box
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.

Scripting Function
The return statement is used to specify the value that is returned from the function.
So, functions that are going to return a value must use the return statement.
<html>
<head>
<script type="text/javascript">
                function product(a,b){
                                return a*b;
                }
</script>
</head>
<body>
<script type="text/javascript">
                document.write(product(4,3));
</script>
</body>
</html>

Scripting Loops
In JavaScript, there are two different kind of loops:
for - loops through a block of code a specified number of times
while - loops through a block of code while a specified condition is true 

Sintax For
<html>
<body>
                <script type="text/javascript">
                                var i=0;
                                for (i=0;i<=5;i++){
                                                document.write("The number is " + i);
                                                document.write("<br />");
                                }
                </script>
</body>
</html>

Sintax While
<html>
<body>
                <script type="text/javascript">
                                var i=0;
                                while (i<=10){
                                     document.write("The number is " + i);
                                       document.write("<br />");
                                        i++;
                                }
                </script>
</body>
</html>

Scripting Event
Events
By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript.
Every element on a web page has certain events which can trigger a JavaScript. For example, we can use the onClick event of a button element to indicate that a function will run when a user clicks on the button. We define the events in the HTML tags.

Event
Fungsi
onLoad
Pertama kali di tampilkan
onClick
Button di Click
onMouseOver
Event pointer masuk ke daerah yang diblok
Dan lain-lain

Scripting Error Handling
When browsing Web pages on the internet, we all have seen a JavaScript alert box telling us there is a runtime error and asking "Do you wish to debug?". Error message like this may be useful for developers but not for users. When users see errors, they often leave the Web page.
The try...catch Statement
The try...catch statement allows you to test a block of code for errors. The try block contains the code to be run, and the catch block contains the code to be executed if an error occurs.
Scripting Special Character
In JavaScript you can add special characters to a text string by using the backslash sign. 

Code
Output
\’
single quote
\”
double quote
\&
ampersand
\\
backslash
\n
new line
\r
carriage return
\t
tab
\b
backspace
\f
form feed

Content Display dalam Halaman Web II

Posted by bahagia bersama dinda :)


Content Display dalam Halaman Web
Hypertext dan Hypermedia
Dokument Hypertext adalah dokumen yang berisi link ke dokumen lain. Anda bisa pindah dari satu dokumen ke dokumen lain hanya dengan klik link tersebut.
Dokumen hypermedia adalah dokumen yang berdasarkan hypertext ditambah dengan multimedia seperti gambar, video dan audio. Dalam dokumen hypermedia, gambar sering digunakan sebagai link ke dokumen lain

ABSOLUTE PATH DAN RELATIVE PATH
Dalam HTML ada dua jenis path, yaitu path absolute da path relative.
Path relative jika lokasi file tersebut relatif terhadap dokumen yang sedang aktif, yaitu terletak di atas atau dibawah direktori dokumen tersebut.
Contoh : <a href=“../tes.html”>masuk !</a>,
                    <a href=“masuk/tes.html”>Mlebu !</a>.
Absolute Path adalah path yang merujuk pada pada suatu lokasi file dengan cara alamat url yang ditulis lengkap atau utuh.
Contoh : <a href=http://www.stikom.edu>Stikom</a>

Link
Link (disebut juga hyperlink atau web link) merupakan dasar pembangun hypertext. Sebuah link menghubungkan satu sumber web ke web lain. Meskipun merupakan konsep sederhana, link telah menjadi satu sumber sukses web.
Link mempunyai dua komponen, yaitu anchor dan tujuan. Link dimulai dari anchor sumber dan berakhir di anchor tujuan yang merupakan sumber web.
•            link merupakan sarana yang membawa anda ke lokasi yang    dituju.
•            Anchor merupakan lokasi yang menjadi tujuan dari link tersebut.
ATRIBUT ID
Atribut href untuk menyatakan suatu file tujuan. Server mencari ke dalam direktori di mana dokumen saat ini berada untuk mencari file tersebut. File dokumen tujuan HTML yang menggunakan elemen A bisa diikuti atribut id.
Untuk membuat link yang membawa pembaca ke suatu bagian tertentu dalam dokumen, cukup sertakan tanda # setelah nama bagian link.
Contoh : <a href=“#teguh”>Oke</a>

JUDUL LINK
Atribut title bisa digunakan dalam elemen A dan LINK untuk menambah informasi tentang link. Informasi ini akan ditampilkan berupa tooltip oleh browser.
Contoh : <a href=“wkwk.html” title=“Beres”>Hahaha</a>

ELEMEN <A>
Untuk membuat suatau link dalam HTML dipergunakan elemen yang dinyatakan dengan tag berpasangan <a>..</a>.
Atribut
Fungsi
Name
Menyatakan titik anchor dalam suatu dokumen HTML
Href
Menunjukan lokasi dokumen Web
Rel
Menggambarkan hubungan dari dokumen asal dengan dokumen tujuan yang ditunjuk dengan atribut href
DLL

Dokumen yang Tidak Ditemukan Browser
Jika suatu dokumen yang link tidak ditemukan oleh browser, ada beberapa keterangan :
•          Jika Browser tidak menemukan lokasi yang ada di link, browser akan memberi keterangan
•          Jika browser tidak bisa mendefinisikan tipe dokument yang di link, browser akan terus mencobanya dan akan memberi peringatan.

HTML Frames
Kegunaan Frame :
•          Membuat daftar isi pada suatu sisi frame sementara sisi frame yang lain menampilkan isi.
•          Membuat suatu judul atau logo yang tidak berubah-ubah pada suatu sisi frame, sedangkan sisi frame yang lain menampilkan isi dokumen.
•          Membuat suatu dokumen tanya-jawab, di mana sisi frame yang satu berisi daftar pertanyaan sedangkan sisi frame yang lain
•          DLL.

Membuat Frame
Dokumen frame tidak boleh berada dalam elemen body. Dokumen frame menggunakan elemen FRAMESET mempunyai dua buah atribut, yaitu ROWS dan COLS.
•          ROWS Membagi Jendela Browser menjadi beberapa baris frame
•          COLS membagi jendela browser menjadi beberapa kolom frame

Tag <frame>
Tag <frame> mendefiniskan sebuah frame. Tag tersebut harus dalam elemen FRAMESET, conoth :
<html>
                <head>
                                <title>frame</title>
                </head>
                <frameset rows="5,5" cols="5,5">
                                <frame src="http://www.google.com">
                                <frame src="http://www.detik.com">
                                <frame src="http://www.facebook.com">
                                <frame src="http://www.yahoo.com">
                </frameset>
</html>

Link ke Sumber (SRC)
Atribut yang paling penting dari tag FRAME adalah SRC (Source). SRC menunjukkan bahwa frame berisi URL, yang biasanya adalah file HTML.
                <frame src=http://www.stikom.edu>
File HTML yang dipanggil oleh SRC diusahakan merupakan dokumen HTML yang lengkap. Artinya harus mengandung elemen HTML, HEAD, BODY dan lainnya. Anda juga bisa memanggil file image (*.jpg) / (*.gif) / (*.png) 

Mengatur Jumlah Baris dan Kolom Frame
Untuk mengatur baris dan kolom frame hampir sama. Aturan penggunaan atribut ROWS dan COLS pada FRAMESET adalah Sebagai Berikut :
<frameset rows="500px,500px" cols="500px,500px">
……………
……………
</frameset>
Nilai baris dan nilai kolom adalah kumpulan nilai yang menyatakan banyaknya frame yang dibuat serta ukuran masing-masing frame

Mengatur Jumlah Baris dan Kolom Frame
UKURAN Frame dengan Pixel
Menentukan tinggi baris dan lebar kolom dalam nilai secara absolut adalah kurang baik, karena tidak semua browser dijalankan pada monitor yang mempunyai resolusi sama, sehingga hasilnya bisa berbeda-beda
Contoh : <frameset rows="5px,5px" cols="5px,5px">
UKURAN Frame dengan Persen
Cara ini lebih baik dari pengaturan frame dengan pixel. Harus diingat bahwa jumlah nilai pengaturan adalah 100%. Jika nilai yang diberikan melebihi 100% maka browser akan menurunkan nilai nya sehingga berjumlah 100%. Demikian jika jumlahnya kurang dari 100% browser akan mengatur sehingga jumlahnya 100%
Contoh : <frameset rows="50%,50%">
UKURAN Frame dengan Nilai Relatif
Contoh : <frameset rows=“4*,*,3*”>

tanda * menyatakan suatu bagian dari sisa ruang yang ada. Di dedepan tanda * tidak ada angka, maka dianggap bahwa angka tersebut adalah 1
Untuk pengaturan di atas, ukuran frame yang pertama adalah 4/7 tinggi jendela browser, frame yang kedua 1/7 tinggi jendela browser, dan frame yang ketiga 3/7 tinggi jendela browser. Angka pembagi 7 didapat dari total jumlah nilai di depan tanda *.

HTML Forms
Form adalah salah satu penampilan interaktif yang paling populer pada World Wide Web(www).
Form memungkinkan pengguna berinteraksi dengan teks, grapik atau yang dirampilkan pada browser.
Sebuah form dibentuk dengan menggunakan pasangan tag <form> </form>. Setiap elemen FORM harus mempunyai 2 buah atribut METHOD dan ACTION.
ACTION adalah URL dari script yang dipanggil oleh form tersebut
Method adalah cara mengirimkan data yang dimasukan pembaca ke web server. Form ini mempunyai dua metode yaitu GET dan POST.
Metode GET Adalah mengirimkan data pada server dengan cara meletakkannya pada bagian akhir URL.
Metode POST Adalah mengirim seluruh data dari form yang terpisah dari URL
Metode GET
<form action = “Proses.php” method = “GET”>
   ……………
   ……………
</form>
Metode POST
<form action = “Proses.php” method = “POST”>
   ……………
   ……………
</form>
Tag
Description
<Form>
Defines an HTML form for user input
<input>
Defines an input control
<textarea>
Defines a multi-line text input control
<select>
Defines a select list (drop-down list)
<option>
Defines an option in a select list
<button>
Defines a push button

HTML Scripting
The <script> tag is used to define a client-side script, such as a JavaScript.
The script element either contains scripting statements or it points to an external script file through the src attribute.
Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
<script type="text/javascript">
                document.write("Hello World!")
</script>
The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.
The noscript element can contain all the elements that you can find inside the body element of a normal HTML page.
The content inside the noscript element will only be displayed if scripts are not supported, or are disabled in the user’s browser:
<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
Tag
Description
<script>
Defines a client-side script
<noscript>
Defines an alternate content for users that do not support client-side scripts


Content Display dalam Halaman Web I

Posted by bahagia bersama dinda :)


Objektif
¡  HTML Text Formating
¡  HTML Styles
¡  HTML Images
¡  HTMLTables
¡  HTML List
HTML Text Formating
HTML uses tags like <b> and <i> for formatting output, like bold or italic text. Examples :
•          This text is bold -> <b>This text is bold</b>
•          This text is italic   -> <i>This text is bold</i>
Tag
Description
<b>
Define Bold Text
<i>
Define Italic Text
<sub>
Define subscripted Text

HTML Styles
Attribut Style
Attribut Style digunakan secara langsung terhadap tag yang berada dalam BODY untuk melakukan pengaturan dengan properti-properti CSS.
Contoh Attribut Style :
<html>
<body style="background-color:Blue;">
       <h1>Look ! Styles and colors</h1>
       <p style = "font-family: verdana; color: red">
                This text Verdana and red
       </p>
        <p style= "font-family: times; color: green">
                This text isi Times and green
        </p>
        <p style= "font-size:30px">
                This text is 30 pixels high
        </p>
</body>
</html>
HTML Images
Mengenal Jenis Gambar
Sebelum mempraktekkan penambahan gambar dalam dokumen web, ada baiknya untuk mengenal berbagi tipe gambar yang dapat ditampilkan oleh browser.
Jenis Gambar
Ekstensi
Keterangan
GIF
.gif
Grapich Interchange Format
JPEG
.jpg / .jpeg
Joint Photographic Experts Group
PNG
.png
Portable Network Graphics

Graphis Interchange Format (GIF)
Gif hanya mendukung 256 warna.msalah satu warna bisa bersifat transparant, yang memungkinkan warna ini tembus terhadap latar belakang. Khusus untuk format GIF87a tersedia fitur interlancing.
Mengingat dukungan warna yang terbatas, GIF cocok untuk membuat gambar yang melibatkan sedikit warna, misalnya logo atau gambar tombol
Joint Photographics Experts Group (JPEG)
Berbeda dengan GIF, JPEG menggunakan 24 bit untuk setiap warna. Dengan demikian, warna yang bisa ditangani mencapai 224 atau 16.777.216 buah. Oleh karena itu, format gambar ini sering disebut “jutaan warna”. Mengingat keadaan seperti ini. JPEG sangat cocok untuk mendukung foto
JPEG tidak mendukung transaparansi dan animasi. Namu JPEG progresif mendukung interlancing
Portable Network Graphics (PNG)
PNG dirancang oleh W3C (World Wide Web Consortium) untuk mengantikan GIF dan JPEG. Formatnya didesain supaya tidak tergantung pada mesin sehingga apapun jenis komputer dan sistem operasi yang digunakan dapat menangani gambar PNG.
Ada dua macam PNG:
•          PNG-8
•          PNG-24
PNG-8 menggunakan 8 bit untuk menyimpan sebuah warna, sedangkan png-24 memakai 24-bit
Terkadang kita jumpai halaman web dengan latar belakang berupa suatu gambar. Latar belakang seperti itu kdangkala mempercantik halaman web.
Untuk menyertakan suatu gambar sebagai latar belakang, anda bisa menggunakan atribut BACKGROUND pada tag <body>. Bentuknya sebagai berikut:
                <body background = “namaberkasgambar”>
<html>
                <head>
                                <title>Latar belakang</title>
                </head>
<body background = “images/tes.png”>
</body
</html>
Menampilkan Gambar
Untuk menampilkan gambar, anda bisa menggunakan tag <img>. Tag ini mempunyai banyak atribut, tetapi hanya satu yang harus disertakan, yaitu atribut SRC
                <img src = “nama_gambar”>
<html>
                <head>
                                <title>Latar belakang</title>
                </head>
<body>
                <img src=“tes.png”>
</body
</html>
Mengatur Letak Teks Terhadap Gambar
Tag <img> menyediakan atribut bernama align yang berfungsi untuk mengatur penempatan teks terhadap gambar.
Nilai
Keterangan
TOP
Teks diletakkan di bagian atas
MIDDLE
Teks diletakkan di tengah-tengah
BOTTOM
Merupakan nilai default. Dalam hak ini, teks diletakkan pada bagian bawah

Mengatur Ukuran Gambar
Bila anda memiliki gambar yang berukuran besar dan bermaksud mengubah ukuran gambar saat gambar ditampilkan, anda bisa mengaturnya melalui atribut pada tag <img> yang bernama height dan width.
•          Height untuk mengatur tinggi gambar
•          Width untuk mengatur lebar gambar
                <img src = “tes.png” height=“20” width=“20”>
<html>
                <head>
                                <title>Latar belakang</title>
                </head>
<body>
                <img src=“tes.png” height=“20” width=“20”>
</body
</html>
HTML Tables
ELEMEN TABLE
Untuk membuat tabel. Anda harus memulainya dengan pasangan tag <table>..</table>. Di dalam tag anda dapat menentukan banyak kolom dan baris. Perataan, warna dan pengaturan lainnya
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<table width="200" border="1">
  <tr>
    <th>Nim</th>
    <th>Nama</th>
  </tr>
  <tr>
    <td>08410100140</td>
    <td>Joni</td>
  </tr>
</table>
</body>
</html>
Atribut Table:
•          Border : untuk membuat batas tepi.
•          Width : untuk mengatur lebar table.
•          Align : untuk mengatur bentuk perataan horizontal data di dalam table. Seperti kiri, tengah, atau kanan
•          DLL.
•          Group Baris
•          Baris tabel bisa dibagi menjadi tabel head. Tabel foot dan tabel body dengan menggunakan elemen THEAD, TFOOT dan TBODY.
•          Tabel head dan tabel tfoot berisi informasi tentang tabel kolom
•          tabel body berisi dari table data.
•          Setiap THEAD, TFOOT dan TBODY berisi group baris dan masing-masing group paling sedikit berisi satu baris didefinisikan dengan elemen <tr>
•          Contoh Group Table
<table>
        <thead>
                        <tr>       
                                        <th > Nama </th>
                                        <th > Hari </th>  
                        </tr>      
        </thead>              
        <tbody>
                        <tr>       
                                        <td > Teguh</td>
                                        <td > Selasa</td>
                        </tr>
        </tbody>              
<tfoot>
        <tr><td colspan="2">footnote</td></tr>
</tfoot>
</table>
HTML Unordered Lists
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items are marked with bullets (typically small black circles).
<ul>
        <li>Coffee</li>
        <li>Milk</li>
</ul>
HTML List
HTML Ordered Lists
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
The list items are marked with numbers.
<ol>
        <li>Coffee</li>
        <li>Milk</li>
</ol>
HTML Definition Lists
A definition list is a list of items, with a description of each item.
The <dl> tag defines a definition list.
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes the item in the list):
<dl>
        <dt>Coffee</dt>
                        <dd>- black hot drink</dd>
        <dt>Milk</dt>
                        <dd>- white cold drink</dd>
</dl>
Tag
Description
<ol>
Defines an ordered list
<ul>
Defines an unordered list
<li>
Defines a list item
<dl>
Defines a definition list
<dt>
Defines an item in a definition list
<dd>
Defines a description of an item in a definition list


Shoutmix