JavaScript Archives
Published by David Walsh on Monday, July 19, 2010 •

More often than not, I find myself wanting to upload more than one file at a time. Having to use multiple “file” INPUT elements is annoying, slow, and inefficient. And if I hate them, I can’t imagine how annoyed my users would be. Luckily Safari, Chrome, and Firefox have implemented a method by which users can upload multiple files within one INPUT element.
The HTML
<!-- IMPORTANT: FORM's enctype must be "multipart/form-data" -->
<form method="post" action="upload-page.php" enctype="multipart/form-data">
<input name="filesToUpload[]" id="filesToUpload" type="file" multiple="" />
</form>
Simply adding the multiple attribute allows for multiple files to be uploaded via one INPUT element. If you’re a stickler for validation, you’ll want to assign the multiple attribute a value of multiple.
Published by David Walsh on Friday, July 16, 2010 •
One of the seldom used attributes within the HTML tag library is the defer attribute on SCRIPT elements. As you can probably tell by the name of the attribute, defer instructs the contents of the script tag to not execute until the page has loaded. Take a look!
Deferring Your Scripts
<script>
//do stuff (runs first)
</script>
<script defer="defer">
//do stuff, but defer it (runs last)
</script>
<script>
//do more stuff (runs second)
</script>
The deferred SCRIPT element’s code will execute once the rest of the page’s resources have loaded. What does this mean? Be sure that your document doesn’t rely on any of the code within the script during page load. In the example above, the middle block will execute once the page has loaded even though it appears before the last block.
Published by David Walsh on Tuesday, July 13, 2010 •
Having thrust myself into the world of JavaScript and JavaScript Libraries, I’ve often wondered: When are browser vendors going to see the helper methods/libraries created by the JavaScript toolkits and implement these functionalities natively within the browser? I realize that standards are important and browser vendors can’t afford to half-ass these implementations but I do believe they could be…expedited. The good news is that one of these functionalities has been add to the HTML5 API; classList.
The classList object, added to all nodes within the DOM, provides developers methods by which to add, remove, and toggle CSS classes on a node. classList also allows developers to check if a CSS class has been assigned to a given node.
Published by David Walsh on Tuesday, July 6, 2010 •
Google recently debuted a new web service called the Font API. Google’s Font API provides developers a means by which they may quickly and painlessly add custom fonts to their website. Let’s take a quick look at the ways by which the Google Font API can be used.
Font Request Format
Many of the fonts within Google’s font archive are available not only in standard format but also in Italic, Bold, and Italic Bold. The format for requesting a given font variant is:
{font}:{variant1},{variant2}
Here are a few examples of requesting each variant:
Published by David Walsh on Monday, June 28, 2010 •

One interesting aspect of web development is Geolocation; where is your user viewing your website from? You can base your language locale on that data or show certain products in your store based on the user’s location. Let’s examine how you can use Geolocation within Firefox to get location details down to the street!
Detecting Browser Geolocation Capabilities
if(navigator.geolocation) {
//w00t!
}
else {
alert('No soup for you! Your browser does not support this feature');
}
They key to detecting Geolocation within your browser is the navigator.geolocation object.