bluephoenix
02-06-2003, 06:58 PM
I don't know about any of you but I've always found it annoying that when you're using a form there's a SUBMIT button and there's a CLEAR FORM button. If there's only two or three fields, clearing the form works great. But if it's a rather lengthy contact/feedback form it would be nice to have a button that just clears the message part of the form and leaves the rest of the fields alone.
It's not a new practice to change the value of fields in a form, but I honestly haven't seen this one implimented yet. It's a short and simple piece of code that I think exemplifies what JavaScript is supposed to do... nonintrusively enhance your webpage. And while nobody will probably ever use it it's very presence tells the viewer that the webdesigner cared enough to think of the little things!
Given a similar form:
<form action="sendform.php" method="post" name="feedback">
<p>
<!-- various input fields -->
Email Address: <input type="text" value="" size="37" name="email" /><br />
Subject: <input type="text" value="" size="37" name="subj" /><br />
Message: <textarea rows="8" cols="42" name="msg" wrap="virtual"></textarea><br />
<input type="submit" value="Send" />
<input type="button" value="Clear Message Field" onclick="clrMsg();" />
<input type="reset" value="Clear Entire Form" />
</p>
</form>
simply insert a function call similar to this in the head of the document:
<script type="text/javascript">
<!--
function clrMsg() {
document.forms.feedback.msg.value = '';
return true;
}
</script>
It's not a new practice to change the value of fields in a form, but I honestly haven't seen this one implimented yet. It's a short and simple piece of code that I think exemplifies what JavaScript is supposed to do... nonintrusively enhance your webpage. And while nobody will probably ever use it it's very presence tells the viewer that the webdesigner cared enough to think of the little things!
Given a similar form:
<form action="sendform.php" method="post" name="feedback">
<p>
<!-- various input fields -->
Email Address: <input type="text" value="" size="37" name="email" /><br />
Subject: <input type="text" value="" size="37" name="subj" /><br />
Message: <textarea rows="8" cols="42" name="msg" wrap="virtual"></textarea><br />
<input type="submit" value="Send" />
<input type="button" value="Clear Message Field" onclick="clrMsg();" />
<input type="reset" value="Clear Entire Form" />
</p>
</form>
simply insert a function call similar to this in the head of the document:
<script type="text/javascript">
<!--
function clrMsg() {
document.forms.feedback.msg.value = '';
return true;
}
</script>