Sunday, 9 January 2011

Javascript: Functions and Variable Declarations

This is Part II of the Javascript Series.


Javascript Functions


We can write functions in Javascript. The coding for functions is this:


function testFunction()
{


}


I prefer to group the {} in one line. It is neater and it is not as confusing. You can see it at the same line. It is useful if there are a lot of functions written.


Functions is used to perform actions that user requires. 


Examples of actions are as below: 

  1. Perform screen navigations from one page to another or opening a popup
  2. Save information to the system
  3. Able to execute server script such as VBScript
  4. Hide and display certain fields 
  5. Perform validation checking
  6. Perform simple calculations
  7. Control how a page is being displayed on the screen


Variable Declarations


Here are how we declare variables in Javascript. There are several ways to declare methods. We can declare variables in one line or multiple lines as shown below.


var a;
var b;


var a,b;


Assigning Variables
After declaring variables, we can assign values to the variables.


var a = "First variable";
var b = "Second variable";


var a = "First variable";var b = "Second variable";


We can also assign value using this method:


var a,b;
a = "First variable";
b = "Second variable";


This concludes the second part on Javascript. We will be looking at "For" loops and "If' statements. It is slightly similar to the style used in Java and C#. 


For your information, Javascript <> Java. 


Cheers,


Rogerkoo

Friday, 7 January 2011

Javascript: Introduction

Javascript is a scripting language used to enhance interactivity to HTML. It is able to detect various events such as onClick (when user clicks on a button or any HTML element), onChange (when user selects a value from a drop down or list box), onBlur (when user clicks outside the HTML element or lost focus), onKeyUp (when user presses a key and releases it) and onKeyDown (when a user presses the keyboard). 


It is also used to control the design of the HTML webpage. This is used together with the events mentioned above. A web designer can use it to control how HTML elements are being displayed on the webpage. It can automatically converts all text that are typed in to uppercases. If a user clicks on a drop down value, the web developer can display those elements that needs to be shown and hide the others.


It can also be used to get the values of a textbox or a drop down or field by using Javascript methods which will be discussed later.


It can be added into the HTML page directly or linked to an external Javascript file (.js). Below is an example of how Javascript is added to the HTML code:


<script type="text/javascript">
    // add javascript coding here.
</script>


Javascript can also be placed to an external file. This is separate the HTML code with the Javascript code. It also enhances the performance of the webpage. The Javascript file will be cached and thus reduces the loading time. It can be linked from HTML to the external Javascript using this code below. For example, my external script name is test.js.


<script type="text/javascript" src="test.js"></script>


Other references:
  1. W3Schools:Javascript Tutorial
  2. Internet.com: How to place Javascripts in External Files

Wednesday, 5 January 2011

Brief Introduction

Welcome to Programmer's Vault. This is the place where you learn and understand programming. It also serves as a programming reference site.


Here's a brief introduction of myself:


I have been working for nearly 4 years in an IT software provider specialising in banking systems. I also have a Bachelor of Computing degree from Monash University. 


Throughout my university and working experiences, I have studied and learned software engineering skills. I also studied the Software Development Life Cycle (SDLC) before.


Here are some of my skillsets:
Javascript
VBScript
SQL & SQL Server Reporting Services
Java
C#.NET / Visual Studio.NET
HTML / XHTML
CSS
XML
MYOB