Javascript 101: Function Fundamentals (Part 5)

Functions are the bread and butter of any programming language, these are reusable sections of script which can execute on an event, condition or user input.

In this tutorial we will look at functions, allowing us to create scripts which are far more complex and interactive, adding real benefit to your web design projects.

Building a Javascript Function

Take a look at a basic function below:

function MyFunctionName ()
{
    alert(“Welcome To Our web Design Project”);
}

This function will not run when the page loads and the script is executed. This is because although the script has run, the function has not actually been called. For a function to execute, you would need to call it from some place else within the script, or from an event in your HTML. See below:

function MyFunctionName ()
{
    alert(“Welcome To Our web Design Project”);
}

MyFunctionName ();

This is the simplest method, and is called when the script is executed.

Consider calling the function from a HTML button?

This is achieved by calling the JavaScript function directly from the “onclick” event in the HTML see below:

<button onclick="JavaScript:MyFunctionName ();">Click Me Please</button>

Whats Next

In the next post we will look at combining the last two posts: variables and function fundamental. Using these two together we will push your scripts 1 step further.

About russell

Web Developer I’m a web developer with 3 years’ experience in the media industry. My Development skills includes flash, AS3, AS2, HTML, CSS, JavaScript, Jquery, XML, PHP, and MySQL. I have a great deal of experience developing interactive user interfaces in PHP Javascript AS3 AS2 I have two masters degrees in Computer Science and Multi Media and before my current role I completed a year of research at De Montfort University researching multi touch technology. during this time I developed several multi touch applications for entertainment spaces.

3 Responses to Javascript 101: Function Fundamentals (Part 5)

  1. Sacramento says:

    Great post about java…

  2. Calgary says:

    Glad to find the information here

    thanks to exchange your thoughts
    & information

  3. Reed says:

    Glad to find the information here.thanks to exchange your thoughts & information.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>