function validate(){ var fields = [ ['nameField', 'name'], ['companyField', 'company'], ['countryField', 'country'], ['phoneField', 'phone'], ['emailField', 'email'], ['enquiryField', 'enquiry'] ]; var errors = 'You must complete the following fields:\n\n'; var errorCount = 0; for(var i = 0, n = fields.length; i < n; ++i){ if($(fields[i][0]).value == ''){ errors += '\t* '+fields[i][1]+'\n'; ++errorCount; } } if(errorCount > 0){ alert(errors); return false; } return true; } window.addEvent('domready', function(){ $('stateField').disabled = true; $('otherField').disabled = true; $('otherField').value = 'Other'; $('stateField').selectedIndex = 0; $('countryField').selectedIndex = 0; $('countryField').addEvent('change', function(){ if(this.value == 'Australia'){ $('stateField').disabled = false; $('otherField').disabled = true; }else{ $('stateField').disabled = true; $('stateField').selectedIndex = 0; $('otherField').value = 'Other'; $('otherField').disabled = false; } if(this.value == 'other'){ $('otherField').disabled = false; $('otherField').value = ''; $('otherField').focus(); $('stateField').disabled = true; $('stateField').selectedIndex = 0; } }); $('otherField').addEvent('blur', function(){ var value = this.value.toLowerCase(); if(value == '' || value == 'other'){ this.value = 'Other'; } }); $('otherField').addEvent('focus', function(){ this.select(); }); //$('contactForm').action = ''; //$('contactForm').addEvent('submit', validateEmail); });