How to disable all the elements of a form using JavaScript

Here’s a little JavaScript function that disables all form elements: functiondisableElements(formName){varfm=document.forms[formName];for(vari=0;i<fm.elements.length;++i){fm.elements[i].disabled=true;}} As you may have noticed the only parameter you need to pass is the form name.

Capturing groups using regular expressions (RegEx) in JavaScript

There are whole books about regular expressions so this post shouldn’t be intended as an exhaustive resource on the subject. It just shows how to extract a substring from a string using regular expressions in JavaScript so it must be considered just a tip not a tutorial on RegExp. Look at the following example: varstr="http://www.alessandrolacava.com/?code=ALE69";varregex=/code=(w+)&?/;varresults=regex.exec(str);if(!results){alert("no match");}else{// first group alert(results[1]);} The previous code extracts the string that follows the code= part of str.

How to compute the timestamp in JavaScript

Many sources use the term timestamp to refer specifically to Unix time, the number of seconds since 00:00:00 UTC on January 1, 1970. In JavaScript you can use the built-in object Date to compute this timestamp. Here follows an example: varts=Date.UTC('2007','09','28')/ 1000;alert(ts); The previous code displays an alert with the number of seconds between 00:00:00 UTC on January 1, 1970 and 00:00:00 UTC on October 28, 2007. How it works: