[Javascript] regex example & code sample

shawn_milochik at godivachoc.com shawn_milochik at godivachoc.com
Fri Apr 30 12:42:08 CDT 2004


                                                                           
             christ at saeweb.com                                             
             Sent by:                                                      
             javascript-bounce                                          To 
             s at LaTech.edu              javascript at LaTech.edu               
                                                                        cc 
                                                                           
             04/30/2004 01:11                                      Subject 
             PM                        Re: [Javascript] regex example &    
                                       code sample                         
                                                                           
             Please respond to                                             
             javascript at LaTech                                             
                   .edu                                                    
                                                                           
                                                                           













> I won't have time to look at your script logic until later today,
> but very quickly my first suggestion is that, instead of this syntax:
>
> onsubmit="if (validatePass('frmCheckPass', 'txtOldPassword',
> 'txtNewPassword1', 'txtNewPassword2') == false){ return false;}"

Good catch. In looking at the code real quick, and thinking about its
possible usage, I would even make it easier by just calling the function
validatePass() without parameters to get it down to:
onSubmit="return validatePassword()"

It's easier on the eyes for futre coders (or for when you yourself have to
revisit this code at a later date). That would avoid the need for eval
statements.


=========================
> >             //declare variables we will use
> >             var returnValue = true;  //will decide whether or not to
submit
> >the form
> >
> >             var strOldPass = eval('document.' + formName + '.' +
oldPass
+
> >'.value');
> >             var strNewPass1 = eval('document.' + formName + '.' +
newPass1
> >+ '.value');
> >             var strNewPass2 = eval('document.' + formName + '.' +
newPass2
> >+ '.value');

=========================

Personally, I never use eval() but would rather access the elements in
their
various collections. Collections are your friend :)

For instance, if you wanted to stick with passing in the parameters, you
could easily do something like this:

var objForm = document.forms[formName]
var objElOldPass = objForm.elements[oldPass]
var objElNewPass1 = objForm.elements[oldPass]
var objElNewPass2 = objForm.elements[oldPass]

Something like this gives you more flexibility because you have all the
properties of the element open to your scripting, rather than specific
properties - the .value in your case.

Say for example you wanted to highlight each field that failed validation.
You could then change it's .class property dynamically. With your previous
code, you'd have to point a new reference to that property.

Otherwise though, good stuff. Keep it coming.

Chris Tifer
http://emailajoke.com

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript






//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




Those are good points.  I guess my inexperience is showing.  I think that
some of the junk I come up with is pretty clever, but
I'm not great on some of the basics, being self-taught.

Thanks to everyone for helping to make my code more elegant.  I'm going to
revise the function based on your suggestions.

Does anyone have any ideas on the "World Times" stuff?  It seems like there
is probably some polishing that can be done,
but I don't see anything that is obvious to me.  It's just that the code is
repetitive for each time zone.  Does JS provide some
way of making each place into some type of object or class or something
with properties which would simplify this?

By the way, I'm going to subscribe under a webmail account
(milo at linuxmail.org) in order to see if the behaviour improves.
It has been pointed out to me off-list that my work e-mail client (Lotus
Notes), is producing weird behaviour in my replies.

Shawn




**********************************************************************
This e-mail and any files transmitted with it may contain 
confidential information and is intended solely for use by 
the individual to whom it is addressed.  If you received
this e-mail in error, please notify the sender, do not 
disclose its contents to others and delete it from your 
system.

**********************************************************************




More information about the Javascript mailing list