View Full Version : string replace problem

12-21-2003, 06:13 PM
Hi I've been trying to sort this out for days now. I hope someone might beable to point me in the right direction.

I have a script where I am seting a globalvariable that is basically a flag. it is a message that has field names concatunated to it when the field validation returns false. When the user fixes the problem in the field and the validation returns true the field name in the message needs to be remove I am removing it using the replace() string method. This works fine however if there is more than one mistake made then the form fieldname is added more than one and for some reason the replace method is one removing on instance of the name rather than all instances. I think the problem is that I'm trying to pass a variable within a variable. Here's my code if anyone could help it would be greatly appreciated. please ignore the focus and blur sections commented out that was something else.

function isDate(val,format,formField) {

var globalAlertMsg = "Please correct the following fields:\n";

var l_Msg = globalAlertMsg.length;

var date=getDateFromFormat(val,format);
if (date==0) {
//eval("document.CurrentForm." + formField + ".select()")
alert("this is " + formField +" has a wrong date");
globalAlertMsg += formField;
return globalAlertMsg;
//eval("document.CurrentForm." + formField + ".focus()")

return false;

else {
alert("this is a right date");

//var editout = " - " + formField + "\n";
var str = globalAlertMsg;

//while(str.search(editout) != -1){
str = str.replace(/formField/g, '');
globalAlertMsg = str;
return globalAlertMsg;

return true;