[Javascript] regex example & code sample

shawn_milochik at godivachoc.com shawn_milochik at godivachoc.com
Fri Apr 30 13:03:52 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










//reply////reply////reply////reply////reply////reply////reply////reply////reply////reply////reply//

The subscription at my other address hasn't completed yet, so I'm replying
here.

I changed the "onsubmit" to:   onSubmit="return
validatePass('frmCheckPass', 'txtOldPassword', 'txtNewPassword1',
'txtNewPassword2');"


However, when I began to go in to change the other things, a couple of
points struck me.

1.  Without passing any parameters, I would have to make a separate copy of
this function for other forms which would use it.  It has been designed
in this case to be "tacked on" to a page over which I have no control of
the form or naming conventions of the text boxes.  So I have to pass the
text box names, and I have to pass the form somehow, in order to allow for
a document with multiple forms.  As is, this .js can be referred to by any
number of pages.

2.  While using "eval" may not be the prettiest or best way, I really
wouldn't get anything out of changing it in *this* case because
I have no need to manipulate the form or any of its contents in this case.
Again, because I'm not really supposed to be doing anything
aside from giving a "helping hand" to the password change page provided by
a third party.

I am grateful for the suggestions though, and keep them coming.  I'll keep
this stuff in mind for future application, but I don't think I need it
here.


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