Javascript Link Calling a Function
Displays Date and Random Number using alert

Javascript Link Calling a Function
Displays Date and Random Number using alert

 
This example shows how to add a custom function. Placing code in custom functions allows you to reuse the same code without repeating it. The function in this case uses the built-in alert function to display a random number. It also shows how to get the current time and date of the user’s computer using the built-in Math class. It includes how you show a line break in and alert dialog using \n. Finally this example shows how to call a function using the a element’s onClick attribute. This attribute’s value is valid Javascript code. Trying to place a lot of complicated Javascript code as the onClick attribute’s value is difficult to edit. The best practice is instead to just add the name of a function followed by the return statement with the false keyword as the expression. Also note that the href attribute’s is set to the hash symbol, # to disable the default browser action for the a element.

Get Javascript Website Skills in 2 Weeks

Javascript website skills needed for interactivity: menus, buttons and forms.