Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force empty form fields on load

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I've seen sites that force form fields to load empty, regardless of the browser's auto-populate settings. How does one do this? I've looked everywhere for info on this but have come up empty.
 
Here is a simple way of doing it.
Code:
<html>

<script type="text/javascript">
<!--//
function clearForm() {
	var el;
	var elements = document.this_form.getElementsByTagName('input');

	for ( var i = 0, el; el = elements.item(i++); ) {
		if (el.getAttribute('type') == "text") {
			el.value = "";
		}
	}
}
//-->
</script>

<body onLoad="clearForm()">

<form name="this_form">
Field 1: <input type="text" name="field1"><br>
Field 2: <input type="text" name="field1"><br>
Field 3: <input type="text" name="field1">
</form>

</body>
</html>

M. Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top