validate form - trim fields

I have an onchange event that trims this paticular field.  I can add this to each tag or is there a way that I can have this automatically implemented across all html fields.

<tr>
<td align="right" nowrap class="faxtext">Address Description: <textarea name="CONTACT_ADDR_DESCR" id="CONTACT_ADDR_DESCR" onchange="trim('CONTACT_ADDR_DESCR', this.value)" cols="32" rows="6" >Location Specific - Directions</textarea></td>
</tr>
LVL 3
gazdzidAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
Try this jquery sample.
It will add change event for all 'textarea' controls on the page and trim.
If you are not familiar with jquery: www.jquery.com
http://api.jquery.com/element-selector/
http://api.jquery.com/jQuery.trim/
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="scripts/jquery-1.4.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('textarea').change(function () {
                alert($(this).val());
                alert(jQuery.trim($(this).val()));
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <textarea id="TextArea1" cols="20" rows="2"></textarea><br />
        <textarea id="TextArea2" cols="20" rows="2"></textarea><br />
        <textarea id="TextArea3" cols="20" rows="2"></textarea><br />
    </div>
    </form>
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hieloCommented:
try putting these in the head of your document:
hieloCommented:
sorry, it got cut off. This is what I had:
<script src="http://code.jquery.com/jquery-latest.js"></script>
	<script type="text/javascript">
	$(function(){
		$(":input").bind('change',function(){
			$(this).val( $.trim($(this).val() ) );
		});
	});
	</script>

Open in new window

govindarajan78Commented:
i hope you do validation while submitting the form, so the trimming there (form onsubmit or button onclick)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.