You are on page 1of 19

Week 13 –

PHP with CSS, JavaScript and Ajax


Objectives
At the end of the module the student is expected to:
• Understand what is Javascript
• Know its advantages and disadvantages in web
development
• Create web application using javascript
• Create application using ajax and its implementation to
php
• Create web app with ajax integrating to tables and
databases
Javascript
• An object-oriented computer programming language commonly used to create
interactive effects within web browsers. JavaScript is an interpreted programming
or script language from Netscape.
• Originally developed by Brendan Eich and originally known as LiveScript, the
programming language JavaScript was renamed in 1995.
• JavaScript is an interpreted client-side scripting language that allows a web designer
the ability to insert code into their web page. JavaScript is commonly placed into
an HTML or ASP file, and runs directly from the web page.
• It is utilized to perform tasks such as printing the time and date, create a calendar, or
other tasks that are not possible through plain HTML.
Hello, World! in JavaScript
<SCRIPT LANGUAGE="JavaScript">
<! -- Hide from old browsers
document.write('Hello World!');
// Stop hide -->
</SCRIPT>

• Although JavaScript files are often embedded into the HTML file, userscan
also save their JavaScript code in an external file. This file often ends with
a .js file extension.
Advantages of JavaScript
• Speed. Being client-side, JavaScript is very fast because any code functions can
be run immediately instead of having to contact the server and wait for an answer.
• Simplicity. JavaScript is relatively simple to learn and implement.
• Versatility. JavaScript plays nicely with other languages and can be used in a
huge variety of applications. Unlike PHP or SSI scripts, JavaScript can be
inserted into any web page regardless of the file extension. JavaScript can also
be used inside scripts written in other languages such as Perl and PHP.
• Server Load. Being client-side reduces the demand on the website server.
Disadvantages of JavaScript
• Security. Because the code executes on the users' computer, in some
cases it can be exploited for malicious purposes. This is one reason some
people choose to disable JavaScript.

• Reliance on End User. JavaScript is sometimes interpreted differently by


different browsers. Whereas server-side scripts will always produce the
same output, client-side scripts can be a little unpredictable. Don't be
overly concerned by this though - as long as you test your script in all the
major browsers you should be safe.
Comparing Javascript and PHP
Comparing Javascript and PHP
Sample Validation of javascript and php
Sample Validation of
javascript and php
JavaScript and DIVs
Parsing data with JavaScript
Using Ajax
• Ajax is a client-side script that communicates to and from a
server/database without the need for a postback or a complete page
refresh. The best definition for Ajax is “the method of exchanging data
with a server, and updating parts of a web page – without reloading the
entire page.
Using Ajax
Another Ajax Example
Displaying Ajax into tables
Ajax and Databases

You might also like