Re: WHile loop to strip characters
by "Mike Taylor" <lonewolf(at)one.net>
|
| Date: |
Tue, 25 Feb 2003 23:45:11 -0500 |
| To: |
<hwg-techniques(at)mail.hwg.org> |
| References: |
aig |
| |
todo: View
Thread,
Original
|
|
Try adding 1 to the line where you reset the value of x:
x.value = x.value.substring(0,l+1)
You might want to name your string something other than the letter "l" as it
looks like a the number 1 under certain fonts. It threw me off for a few
seconds. ;)
HTH,
Mike
----- Original Message -----
From: "Kortland, Brian" <Brian.Kortland(at)AIG.com>
To: <hwg-techniques(at)mail.hwg.org>
Sent: Tuesday, February 25, 2003 1:01 PM
Subject: WHile loop to strip characters
> HI All,
>
> I have a form which is going to have comma separated values pasted into it
> but I would like to make sure to strip off any unwanted spaces or returns
> that may trail at the end, because they cause array errors on my backend
> processing.
>
> I am under the assumption my loop should continue until any invalid
charters
> are stripped off the end of my field contents, until a number is reached.
> This is triggered by either an onchange or onblur. What is happening is
the
> last (invalid) character is properly stripped off but the loop does not
seem
> to reiterate. If I keep forcing blur events it continues removing one
> invalid character at a time until all trailing invalid characters are
> removed. I want this all cycled through the loop. Does anyone see the err
of
> my scripting which is breaking my looping sequence?
>
> x = the textarea object I am passing
> valid = my valid character list
> indexOf = will return -1 if my temp character is not in the valid list
> temp = the last character in my field
> substring = will cut off the last character
>
> function testchange(x){
> var valid = "0123456789"
> var l = (x.value.length - 1)
> var temp = x.value.charAt(l)
> while (valid.indexOf(temp) == -1)
> {
> var l = l - 1;
> x.value = x.value.substring(0,l)
> temp = x.value.charAt(l)
> }
> }
>
> Thanks All!!
>
> Brian
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.