Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Remove default value on input field focus

This code will allow you to remove text inside an input field when focus is given to it.

onFocus="this.value=''"


This is how the code should look while in use:
<input type="text" name="email" id="email" onFocus="this.value=''" value="your email address here" />

javascript value of selected option

// what is the value of the selected option?

this.options[this.selectedIndex].value

Javascript clear and recall default form value

// Swap out default text in a form field on click, and recall if field is empty

<script type="text/javascript">
function clickclear(thisfield, defaulttext, color) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
		if (!color) {
			color = "000000";
		}
		thisfield.style.color = "#" + color;
	}
}
function clickrecall(thisfield, defaulttext, color) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
		if (!color) {
			color = "cccccc";
		}
		thisfield.style.color = "#" + color;
	}
}
</script>

Javascript clear and recall default form value

// Swap out default text in a form field on click, and recall if field is empty
// Example: <input type="text" value="Enter text" onclick="clickclear(this, 'Enter text')" onblur="clickrecall(this,'Enter text')" />

<script type="text/javascript">
function clickclear(thisfield, defaulttext, color) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
		if (!color) {
			color = "000000";
		}
		thisfield.style.color = "#" + color;
	}
}
function clickrecall(thisfield, defaulttext, color) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
		if (!color) {
			color = "cccccc";
		}
		thisfield.style.color = "#" + color;
	}
}
</script>

Javascript clear and recall default form value

// Swap out default text in a form field on click, and recall if field is empty
// Example: <input type="text" value="Enter text" onclick="clickclear(this, 'Enter text')" onblur="clickrecall(this,'Enter text')" />

<script type="text/javascript">
function clickclear(thisfield, defaulttext, color) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
		if (!color) {
			color = "000000";
		}
		thisfield.style.color = "#" + color;
	}
}
function clickrecall(thisfield, defaulttext, color) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
		if (!color) {
			color = "cccccc";
		}
		thisfield.style.color = "#" + color;
	}
}
</script>