Вы находитесь на странице: 1из 2

POLITEKNIK SEBERANG PERAI

JABATAN KEJURUTERAAN ELEKTRIK


PSP

MODULE CODE : F3026 MODULE : WEB AUTHORING


LABSHEET : 09 DATE :
TITLE : Understanding Javascript Functions

Objective :
At the end in this session, the student will be able to :
1. Understand javascript functions.
Tools/Software :
1. Microsoft Notepad
2. Microsoft Internet Explorer

Description:

Functions in Javascript

Use functions in javascript to do pretty much anything your heart desires, learn how to
create a function and use it in this labsheet. For this labsheet, make sure that you have
javascript enabled in your web browser or you wont be able to see the results!

The basic syntax of a function is very same to that of PHP. You must first declare that you
are creating a new function, then you give your function a name, then you put the code
you would like to execute.

For the function that we are going to create, we are going to just create 4 buttons and
each button will say something different when you click on it depending on the information
you pass through your function.

1) Create a new HTML file and save it as javascript_form.html. Write down all following
code.

This piece of code starts off our new HTML document, then we start off our <head> tag,
next we tell the browser that we are creating some new javascript.

Why we should added the <!-- before the function, this is because older browsers that do
not support javascript will just read this javascript as a comment and it won't display. So it
is just used to hide the javascript from older browsers.

Next we declare that we are creating a new function, then we have given our function the
name of companySlogans. Next in our companySlogans function we give it a parameter to
pass information so that it can be processed.

Prepared by Kamarulzaman© (JKE-PSP) 2006


For this we will just be creating a simple alert box to use with this function. So we use the
alert() function, then you can use in the alert() function we have put the words slogan
(This is the same as we have put in our companySlogans() function.)

2) Create another html file and copy all following code. Save it as
javascript_form2.html. Then we close off our form, body and html tags. Our finalized
code should look like this,

3) Try test your page and see the result.

Exercises:
1. Modify the javascript above with your own creativity.
2. Please take a screenshot of your page with the coding and submit it in hardcopy
(printed form) next week.
3. Don t forget to write out the conclusion of your HTML lesson today.

Prepared by Kamarulzaman© (JKE-PSP) 2006

Вам также может понравиться