[Javascript] Question

Craig Gardner CGardner at JohnBurnham.com
Fri Aug 9 17:35:59 CDT 2002


Hello there,

Here's what I'm trying to do:

I want a form, where there are multiple date fields, but if the user
enters
the date unformatted, I want to have the field automatically formatted
to be
in MM/DD/YY format.

Here's what I have:
----snip----
<html>
 <head> 
  <script language='javascript'>
   function format_date(input_date)
   {
    if(!(input_date.charAt(2) == '/') && !(input_date.charAt(5) == '/'))
    {
    
     var mm = input_date.slice(0, 2);
     var dd = input_date.slice(2, 4);
     var yy = input_date.slice(4, 6);

     var new_date = mm + '/' + dd + '/' + yy;

/* This is the part I don't think is working properly.  I know that
"this.value" is wrong, but I can't figure out what should go there to
make
it work.  If I use "document.input.date.value" it does work, but only
for
the one field.*/
     this.value = new_date;
    }
   }
  </script>
 </head>
 <body>
  <form name='input'>
   <input type='textarea' name='date' onblur='format_date(this.value)'
value='MM/DD/YY' onfocus='this.value="";
document.input.returned.value=""'>
   <input type='textarea' name='returned'
onchange='format_date(this.value)'>
  </form>
 </body>
</html>
----snip----

Here's my problem:
It works great, except that it won't work for more than one single
field.
How can I make it work for multiple fields.  Or if I'm going about this
completely wrong, please direct me to a better method.

Thanks,
Craig
  ======================================

  Confidentiality Notice:   The information contained in this electronic
document is considered a confidential and/or privileged communication
between John Burnham Insurance Services and the addressee(s). If the
recipient(s) of this email communication is not the addressee(s), such
recipient(s) is strictly prohibited from photocopying, distributing or
otherwise using this email or its contents and/or attachment(s) in any
way.  If you received this message in error, please contact the sender
listed above by any contact means listed. Thank you!




More information about the Javascript mailing list