|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > replace string problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|