? Earlier 2 items total Later ?

On this page:?

Clear form with Javascript

Purpose: Clear all text fields in a form

Other important features:
- Resulting page must be valid XHTML 1.1
- JS must work in Firefox 1.0 and MS Internet Explorer 6.0
- JS must never generate any errors, even non-fatal ones, in the Firefox Javascript Console
- JS should only clear text input (no hidden fields or visual controls)
- Code must be readable and properly indented

Looking around the web, this was not easy to find. After a few hours of searches, and some back'n'forth at Webmaster World, I got a working version.

In XHTML header:


In html/form/div


In clear-form-input.js:

function clearForm(formIdent) 
{ 
  var form, elements, i, elm; 
  form = document.getElementById 
    ? document.getElementById(formIdent) 
    : document.forms[formIdent]; 

        if (document.getElementsByTagName)
        {
                elements = form.getElementsByTagName('input');
                for( i=0, elm; elm=elements.item(i++); )
                {
                        if (elm.getAttribute('type') == "text")
                        {
                                elm.value = '';
                        }
                }
        }

        // Actually looking through more elements here
        // but the result is the same.
        else
        {
                elements = form.elements;
                for( i=0, elm; elm=elements[i++]; )
                {
                        if (elm.type == "text")
                        {
                                elm.value ='';
                        }
                }
        }
}
        
function addEvent(elm, strEvent, fnHandler)
{
        return ( elm.addEventListener
        ? elm.addEventListener( strEvent, fnHandler, false)
        : elm.attachEvent( 'on'+strEvent, fnHandler)
        );
}

proxy.pac file for Firefox / Mozilla / et. al.

Quite useful for mobile users who work at different locations and require different proxy server settings for each location, just point your Automatic Proxy Configuration URL to your local proxy.pac file and it automatically pics up if it should use a proxy server or not.

function FindProxyForURL(url, host)
{
   if (isPlainHostName(host) ||
       dnsDomainIs(host, ".foobar"))
       return "DIRECT";
    else
        if (isInNet(myIpAddress(), "192.168.99.0", "255.255.0.0"))
            return "PROXY 192.168.99.2:3128; DIRECT";
        else
            return "DIRECT";
}

? Earlier 2 items total Later ?