JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old December 21st, 2003, 11:15 AM
n_benton99 n_benton99 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 n_benton99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
replace string problem

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) {

//document.CurrentForm.elements[formField].select();
var globalAlertMsg = "Please correct the following fields:\n";

var l_Msg = globalAlertMsg.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;
return globalAlertMsg;
//eval("document.CurrentForm." + formField + ".focus()")

return false;

}
else {
alert("this is a right date");
//document.CurrentForm.elements[formField].blur();
alert(globalAlertMsg);

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



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



return true;
}
}



TIA

NIKKI

Reply With Quote
  #2  
Old December 21st, 2003, 04:52 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Why store the error message after showing the user?

They way I would do it:
You have your form full of fields that the user has to fill out. They fill it out but make some errors.
Use the onSubmit event handler to run your validation function.
At the start of the function, initialise the message variable.
Your validation function goes thru and concatenates the error messsage onto the variable as usual.
If there are errors, display to the user. Return false so the form does not submit.

Let the user attempt the fill out the form again. They hit submit to start the validation process again.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > replace string problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway