nbenton99
12-19-2003, 10:47 AM
Hi, I'm trying to do a simple or not so simple string replacement with a variable. The problem I'm having is that it is only replaceing one instance of the variable rather than every instace within the string.
here's all my code.
var globalAlertMsg="Please correct the following fields:\n";
var l_Msg = globalAlertMsg.length;
function formCheck(){
if (globalAlertMsg.length == l_Msg){
return true;
}else{
alert(globalAlertMsg);
return false;
}
}
function isDate(val,format,formField) {
//document.CurrentForm.elements[formField].select();
var alertMsg = "Please correct the following fields:\n";
var l_Msg = alertMsg.length;
var date=getDateFromFormat(val,format);
if (date==0) {
//document.CurrentForm.elements[formField].select();
//eval("document.CurrentForm." + formField + ".select()")
alert("this is " + formField +" has a wrong date");
globalAlertMsg += " - " + formField + "\n";
return globalAlertMsg;
//eval("document.CurrentForm." + formField + ".focus()")
return false;
}
else {
alert("this is a right date");
//document.CurrentForm.elements[formField].blur();
alert(globalAlertMsg);
editout = " - " + formField + "\n";
str = globalAlertMsg;
while(str.search(editout) != -1){
str = str.replace(editout, '');
globalAlertMsg = str;
return globalAlertMsg;
}
alert (str);
alert(globalAlertMsg);
return true;
}
}
Here's the section I'm having trouble with.
alert("this is a right date");
//document.CurrentForm.elements[formField].blur();
alert(globalAlertMsg);
editout = " - " + formField + "\n";
str = globalAlertMsg;
while(str.search(editout) != -1){
str = str.replace(editout, '');
globalAlertMsg = str;
return globalAlertMsg;
}
Any help would be much appreciated.
TIA
Nikki
here's all my code.
var globalAlertMsg="Please correct the following fields:\n";
var l_Msg = globalAlertMsg.length;
function formCheck(){
if (globalAlertMsg.length == l_Msg){
return true;
}else{
alert(globalAlertMsg);
return false;
}
}
function isDate(val,format,formField) {
//document.CurrentForm.elements[formField].select();
var alertMsg = "Please correct the following fields:\n";
var l_Msg = alertMsg.length;
var date=getDateFromFormat(val,format);
if (date==0) {
//document.CurrentForm.elements[formField].select();
//eval("document.CurrentForm." + formField + ".select()")
alert("this is " + formField +" has a wrong date");
globalAlertMsg += " - " + formField + "\n";
return globalAlertMsg;
//eval("document.CurrentForm." + formField + ".focus()")
return false;
}
else {
alert("this is a right date");
//document.CurrentForm.elements[formField].blur();
alert(globalAlertMsg);
editout = " - " + formField + "\n";
str = globalAlertMsg;
while(str.search(editout) != -1){
str = str.replace(editout, '');
globalAlertMsg = str;
return globalAlertMsg;
}
alert (str);
alert(globalAlertMsg);
return true;
}
}
Here's the section I'm having trouble with.
alert("this is a right date");
//document.CurrentForm.elements[formField].blur();
alert(globalAlertMsg);
editout = " - " + formField + "\n";
str = globalAlertMsg;
while(str.search(editout) != -1){
str = str.replace(editout, '');
globalAlertMsg = str;
return globalAlertMsg;
}
Any help would be much appreciated.
TIA
Nikki