Category «Javascript»

Why you should stop using onload method.

Waiting for onload

It is amazing that many web developers still use onload method embedded in the BODY tag, like <HEAD> <BODY onload=”document.contact.userID.focus();”> <form name=”contact”> <input type=”text” name=”userID” > </form> </BODY> </HEAD> There are two problems with this line of code. Embedding code (behavior) with HTML (structure) makes it difficult to maintain the page. onload() method will executes …

Nine Must Have JavaScript Tools For Every Web Developer

Almost all major web development projects include some javascript. Developing Javascript may be easy for some but working around various browsers’ incompatiblities makes it a bit more tedious chore. As a developer I always welcome the opportunity to use development tools that may help in the development process. Following is a list of some useful …

Validate email address using JavaScript regular expression

Last month I wrote about regular expressions in Java, today I’ll show you how to use regular expression in JavaScript to validate email address. Here is the code to validate email address in JavaScript using regular expression. function validateEmail(elementValue){ var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(elementValue); } Explanation: The argument to this method is the email …

Set focus on the first text field of HTML form.

A HTML form is a very good channel that you can offer to your visitors to contact you. An aesthetically appealing form encourages user to fill and submit it. It is equally important to make the form as user friendly as possible. Today I’ll share a small JavaScript function that will set the focus on …