sponsor

Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Tuesday, February 19, 2008

Javascript Explode Implode

JavaScript equivalent of PHP explode function

In PHP we can easily break a long string into smaller parts by using the explode() function of PHP. In run rime, this function works like this:

$string="My Name Is Wahyu Pramusinto";
$string2=explode(" ", $string);


After the execution of the second command the variable $string2 is an array such that,

$string2[0]="My"
$string2[1]="Name"
$string2[2]="Is"
$string2[3]="Wahyu"
$string2[4]="Pramusinto"

and so on. So how do we do it in JavaScript. In JavaScript there is a split() function that achieves the same objective, although the syntax is a bit different.

var string="My Name Is Wahyu Pramusinto";
var string2=string.split(" ");

Now the variable string2 has all those words.



Monday, January 7, 2008

Getting Started with jQuery

This guide is an introduction to the jQuery library. Basic knowledge of JavaScript and the document object model (DOM) is required. It starts from ground up and tries to explain details where necessary. It covers a simple hello world example, selector and event basics, AJAX, FX and usage and authoring of plugins.

This guide contains no "click me" examples. The intention of providing only "copy me" code is to invite you to try it for yourself. Copy an example, see what it does, and modify it.

Setup

To start, we need a copy of the jQuery library, which we can get from the main download page. The jQuery Starterkit provides some markup and CSS to work with. After downloading and extracting its content we put jquery.js into the same directory and open starterkit.html and custom.js with our favorite editor and starterkit.html with a browser.

Now we have everything to start with the notorious "Hello world" example.

Hello jQuery

We start with an empty html page:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// we will add our javascript code here
</script>
</head>
<body>
<--- we will add our HTML content here -->
<body>
<html>

This page just loads the jquery.js library (make sure the URL points to where you stored your copy of jquery! This example assumes that you store it in the same directory as this example file). Two comments indicate where we will expand this template with code.

As almost everything we do when using jQuery reads or manipulates the document object model (DOM), we need to make sure that we start adding events etc. as soon as the DOM is ready.

To do this, we register a ready event for the document.

$(document).ready(function() {
// do stuff when DOM is ready
});

Putting an alert into that function does not make much sense, as an alert does not require the DOM to be loaded. So lets try something a little more sophisticated: Show an alert when clicking the link.

$(document).ready(function() {
$("a").click(function() {
alert("Hello world!");
});
});

This should show the alert as soon as you click on the link.

Lets have a look at what we are doing: $("a") is a jQuery selector, in this case, it selects all a elements. $ itself is an alias for the jQuery "class", therefore $() constructs a new jQuery object. The click() function we call next is a method of the jQuery object. It binds a click event to all selected elements (in this case, a single anchor element) and executes the provided function when the event occurs.

This is similar to the following code:

Link

The difference is quite obvious: We don't need to write an onclick for every single element. We have a clean separation of structure (HTML) and behavior (JS), just as we separate structure and presentation by using CSS.

With this in mind, we explore selectors and events a little further.

Monday, August 20, 2007

Membuat Halaman Login Dengan PHP, MySQL, AJAX, Script.aculo.us dan Prototype.js (bag 2)

Oke, sekarang akan saya lanjutkan tutorial yang kedua. Saya anggap Anda sudah mendownload script.acyulo.us dan prototype.js. Kalo belum, silakan anda download lebih dahulu.
Silakan buka file login.php dan ubah menjadi sebagai berikut.
login.php


buat juga CSS nya dan simpan dengan nama style.css


sampai sejauh ini, kita udah membuat 2 buah file, yaitu login.php dan style.css, selanjutnya kita harus membuat satu file lagi yaitu ajax.php yang akan digunakan untuk mengecek login. Kita juga butuh sebuah database yang berisikan username dan password. Tunggu tutorial bagian ke-3 ya....

Thursday, August 16, 2007

Membuat Halaman Login Dengan PHP, MySQL, AJAX, Script.aculo.us dan Prototype.js (bag 1)

Dalam tutorial kali ini, saya akan menjelaskan bagaimana cara membuat halaman login dengan PHP, MySQL, AJAX, ScriptAculous dan Prototype.js. Untuk mengikuti tutorial ini, Anda sebaiknya sudah mengerti konsep webserver, PHP, dan database MySQL. Kalo belum, sebaiknya Anda mempelajarinya terlebih dahulu. Anda juga harus mengerti AJAX, ScriptAculous dan Prototype.js. Kalo belum mengerti, sebaiknya baca tutorialnya di sini dulu.

Oke, kita mulai saja ya... Pertama Anda harus menyiapkan sebuah halaman HTML untuk login. Kita beri nama "login.php".


saya rasa untuk tag HTML tidak perlu saya jelaskan lagi. Itu adalah tag HTML untuk membuat halaman login yang terdiri dari textbox username dan password. Dalam HTML di atas juga saya buatkan sebuah div untuk menampung hasil error ketika proses login berlangsung. Untuk mengikuti tutorial login bagian ke2, sebaiknya Anda download dulu library prototype.js dan scriptaculous. Tunggu tutorial bagian keduanya ya....