473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1235
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: J. Hall | last post by:
Hi dudes, Got a simple webpage, with three numeric text input boxes, the idea being that the user is asked to insert percentages of their business around the world... UK, Europe, Other ...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I donīt know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
2
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
4
by: bmgz | last post by:
I have a simple DHTML gallery: <script> viewPhoto(thumb){ function viewPhoto(thumb){ document.getElementById('mainPhoto').src=thumb.href; return false; } </script>
11
by: samuelberthelot | last post by:
Hi, I've got 3 input HTML (dropdown lists) on my page. One for selecting a Month, one for the day, one for the year. Very simple... My problem is that I'd like to update the Days one according...
13
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.