[thelist] Something wrong with replace (javascript)

Tom Dell'Aringa pixelmech at yahoo.com
Tue Jul 2 16:54:01 CDT 2002


Amazon,

Its probably because you are really using a regular expression.
replace is not really a method as it were. (that I know of)

You aren't giving the regexp enough info for it to do its stuff.

new SSNString = originalSSNString.replace(/-/g, "");

The above replaces all the occasions of dashes in SSN with a blank.
the g is for global.

So what you need to work in is this:

text = text.replace(/x/g, "y");

that will take all the x's and make them y's

Tom


--- Amazon Paulo <Amazon.Paulo at Amazoniacelular.com.br> wrote:
> Hello everyone,
>
> I'm having trouble with a simple function. In fact, "replace" is
> not working
> as I thought it was going to... It should (?) replace ALL matches
> in a
> string, but is replacing just the first one.
>
> my code:
> <script>
> function formatField(fieldName){
> 	var formatedField = fieldName.replace('x','y');
> 	fieldName.value = formatedField;
> }
> </script>
> <input type="text" onchange="formatField(this);">
>
> Is something wrong? I've tried many different ways to do it
> unsuccesful... I
> type "xxx" in the field and it returns "yxx".
>
> Paulo Guedes
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !


=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com



More information about the thelist mailing list