?
Solved

onChange or onBlur remove leading spaces

Posted on 2005-05-03
10
Medium Priority
?
296 Views
Last Modified: 2008-02-26
This should be an easy one and I've tried about a dozen different pieces of code to do this but nothing is working.

I would like to be able to remove leading spaces from required text boxes in my form before validating. onSubmit is where my validation is called.

Thanks!
0
Comment
Question by:allbird79
  • 6
  • 4
10 Comments
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13919681
Hi allbird79,

Try this:
    element.value = element.value.replace(/^\s+/g, '')

---
German Rumm.
0
 

Author Comment

by:allbird79
ID: 13919704
I added: onChange="element.value = element.value.replace(/^\s+/g, '');" to the end of the text box tag.

It didn't remove the space in the form.

Did I not put it in the code properly?
0
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13919740
allbird79,

Better use onBlur(), there are some problems with onchange event handler when it changes contents of element it is attached to.

Or, you can do it in onSubmit() event handler, you are performing validation there anyway.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:allbird79
ID: 13919827
I changed it to onBlur and it didn't work.

I've never figured out how to combine two events when using onSubmit. Currently my onSubmit is in my form tag and looks like this:
<form ... onSubmit="MM_validateForm('customerName','','R','companyName','','R','city','','R','province','','R','remarks','','R');return document.MM_returnValue">

How would I add the code you've provided?
0
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13919901
allbird79,

ok, you are using DW validation, don't want to mess with that. You textbox should look like this:

<input type="text" onblur="this.element = this.element.replace(/^\s+/g, '');" />
0
 
LVL 6

Accepted Solution

by:
German_Rumm earned 200 total points
ID: 13919906
oops, my mistake:

onblur="this.value = this.value.replace(/^\s+/g, '')"
0
 

Author Comment

by:allbird79
ID: 13920151
I really don't want to mess with it :)

This is not working either...
The entire line is:

<input type="text" name="customerName" class="normal" size="40" onblur="this.value = this.value.replace(/^\s+/g, '')">

Do you see any errors?

0
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13920358
allbird79,

Strange.
http://www.car.ee/EE/Q_21411101.htm - tried that, everything worked in both IE and FF.
Do you want to remove leading spaces or trailing spaces?
0
 

Author Comment

by:allbird79
ID: 13920380
Sorry about that, I tested the wrong page that last time. It is working!!
Thanks,
Appreciate your help on this one.
0
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13920478
allbird79,

Thanks :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question