469,917 Members | 1,473 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Simple Javascript Problem

Jim
Hello,

I have a simple problem which I am guessing has an easy answer within
JavaScript.

I have a form1 with two fields, field1 and field2. I want the contents of
field1 to be transferred to field2 onBlur, but with some changes.

I want the contents of field1 to have its spaces replaced with Dashes, and
all punctuation removed, so this can happen:

FIELD 1 value:
Today's rate is 15%, & the outlook is good.

onBlur should then create a value of:

FIELD 2 value:
todays-rate-is-15-percent-and-the-outlook-is-good

Notice that the "&" was converted to "and", the "%" to "percent". The comma
was deleted and all spaces replaced with Dashes. The second field should
only every contain alphabetic letter, dashes, and numbers.

Any ideas guys?

Cheers,

Jim.
Jul 23 '05 #1
3 1163
Jim wrote:
Hello,

I have a simple problem which I am guessing has an easy answer within
JavaScript.

I have a form1 with two fields, field1 and field2. I want the contents of
field1 to be transferred to field2 onBlur, but with some changes.
onChange would be a better event handler to use instead of onBlur.
I want the contents of field1 to have its spaces replaced with Dashes, and
all punctuation removed, so this can happen:
FIELD 1 value:
Today's rate is 15%, & the outlook is good.

onBlur should then create a value of:

FIELD 2 value:
todays-rate-is-15-percent-and-the-outlook-is-good

Notice that the "&" was converted to "and", the "%" to "percent". The comma
was deleted and all spaces replaced with Dashes. The second field should
only every contain alphabetic letter, dashes, and numbers.


Create a simple object or array that has all of the possible % & ^ @
that you want converted to words. Then you do a RegExp replace on them.
Then you create a second table of entries for puntuation that you want
replaced. Then you loop through the string and replace puntuation. Then
you replace spaces with Dashes.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
Jim
> Create a simple object or array that has all of the possible % & ^ @ that
you want converted to words. Then you do a RegExp replace on them. Then
you create a second table of entries for puntuation that you want
replaced. Then you loop through the string and replace puntuation. Then
you replace spaces with Dashes.

OK..... :)
Can you provide a really simple example? I haven't really got a clue where
to start (here? :) )

Jim.
Jul 23 '05 #3
Jim wrote:
Create a simple object or array that has all of the possible % & ^ @ that
you want converted to words. Then you do a RegExp replace on them. Then
you create a second table of entries for puntuation that you want
replaced. Then you loop through the string and replace puntuation. Then
you replace spaces with Dashes.


OK..... :)
Can you provide a really simple example?


Start by posting a list of punctuation you want converted, along with
what they should be converted to. Then add a list of punctuation you
want removed. Then consider this sentence:

Should the period in 123.27 be removed or left alone? It is not as
simple a prospect as you might think it is.

Also, should it's be changed to it is or to its?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by J. Hall | last post: by
reply views Thread by 42 | last post: by
18 posts views Thread by Q. John Chen | last post: by
73 posts views Thread by Claudio Grondi | last post: by
27 posts views Thread by one man army | last post: by
4 posts views Thread by bmgz | last post: by
11 posts views Thread by samuelberthelot | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.