HTML5 tests - checking input types with JS

To tests.

It is possible in most browsers to use JavaScript to detect support for specific input types. This page uses my script.

color

email

number

range

tel

url

date

datetime

month

time

week

Script

I use the following script:

function supportsType(input) {
	var desiredType = input.getAttribute('type');
	var supported = false;
	if (input.type === desiredType) {
		supported = true;
	}
	input.value = 'Hello world';
	var helloWorldAccepted = (input.value === 'Hello world');
	switch (desiredType) {
		case "email":
		case "url":
			if (!input.validationMessage) {
				supported = false;
			}
			break;
		case "color":
		case "date":
		case "datetime":
		case "month":
		case "time":
		case "week":
			if (helloWorldAccepted) {
				supported = false;
			} 
			break;
	}
	return supported;
}

See this blog post for an explanation.