Using JavaScript‘s history object a back button can be added to the web page, passing the browser back to the previous page. The action may either be implemented in a form, or with the use of a hyperlink. The example given below shows the form implementation. An onclick has been added to the form button […]
Category: JavaScript
Writing to the Browser Status Bar
The browser status bar property window.status can be modified using JavaScript. Thus to put a website welcome message in the status bar: window.status = ‘Welcome to our website’; If this action is to be repeated a function may be used. In the example below the function setStatus takes the parameter strStatus, a text variable. The […]
Remove Hint Text in Textbox on Click
Info text can be added to a text box, either as instructions, or sample wording, with an onclick emptying the box when the user clicks to enter their content. The textbox is pre-populated with the initial text. A JavaScript onclick action is added to the text box emptying the content when the user enters their […]
For Loop in JavaScript
A JavaScript for loop takes the parameters initialisation, condition and loop end expression. The parameters conditions and expressions associated with the for loop are wrapped within brackets. for(var i = 0; i < parameters.length; i++) { repeated action here } The example shown above, may be used to work through each of the entries in […]
Block Right Mouse Click
Clicking on the right mouse button can be disabled using JavaScript. It is also possible to be more selective, blocking the right click on specific items. The simplest method to disable the mouse right click on a website is through the use of a JavaScript function, acting on the document context: <script type=”text/javascript”> document.oncontextmenu = […]
Ensuring Form Field Content onSubmit
I needed to ensure that a form field had content before the form was submitted. Using a JavaScript function with the onSubmit event I was able to check the a field had content before submitting the form. For a field called firstName add the following into the head of the page <script type=”text/javascript”> <!– function […]
JavaScript isNumeric Function
JavaScript doesn’t have an isNumeric function. A function needs to be created to provide the isNumeric check of a string of characters. The isNumeric function is passed a string of text, which is then checked against a list of valid characters. function IsNumeric(strText) { var validChars = “0123456789.”; var cChar; for (i = 0; i […]
JavaScript Timeout
JavaScripts timeout allows a preset delay before a function is called. Timeouts in JavaScript can be used to create a repeat, for example to slide a div, creating a scrolling marquee effect. The timeout is based on the setTimout() method. setTimout() can take two parameters, the first can be a function reference and the second […]
Email Address Validation
Regular expressions can be used with JavaScript to validate a form email address entry. The function below accepts a form and performs the text on the textbox field with the ID of Email. function validateEmail(frmAddress) { //Validating the email field var rgxp = /^(([^<>()[\]\\.,;:\s@\”]+(\.[^<>()[\]\\.,;:\s@\”]+)*)|(\”.+\”))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ if (! frmAddress.Email.value.match(rgxp)) { alert(“Invalid email address”); frmAddress.Email.focus(); frmAddress.Email.select(); return (false); […]
JavaScript Case Statement
The JavaScript case statement enables one of a series of actions to be chosen, given the value or an expression. Consider the IF clause: If (Style == ‘parent’) { //actions associated with this menu style. } //(Style == ‘parent’) This may be extended to provide an exception if this is not true: If (Style == […]


