I can not get a strings replace() method to work

Giganews Newsgroups
Subject: I can not get a strings replace() method to work
Posted by:  Jake Barnes (lkrubn…@geocities.com)
Date: 7 Sep 2006

I need to change imageUploadInfo2 to caption2 where the number at the
end is a variable that needs to be preserved (imageUploadInfo1 to
caption1, imageUploadInfo43 to caption43, etc)

Can anyone tell me why the following code doesn't work? In the alert at
the bottom I still get "imageUploadInfo2" (which starts off in
idOfInputThatNeedsToHaveItsImageInputUpdated).

idOfInputWhoseCaptionWeWillUpdate =
idOfInputThatNeedsToHaveItsImageInputUpdated;
var textToChange = "imageUploadInfo";
var regX = new RegExp(textToChange, "i");
idOfInputWhoseCaptionWeWillUpdate.replace(regX, "caption");
alert("the input name is " + idOfInputWhoseCaptionWeWillUpdate);

I've also forgotten if Javascript passes values by value or by copy. I
assume by value, or my code is going to become a horrible mess.

Replies