javascript functions passing arguments

by "Peter Newton" <c-newton(at)ihug.co.nz>

 Date:  Tue, 6 Mar 2001 15:51:15 +1300
 To:  <hwg-languages(at)hwg.org>
  todo: View Thread, Original
Hello All,

OK I've created a form asking for name and address.
in the name entry I have a DEFAULT value of:-
'Type your full name here'

in the address field I have a DEFAULT value of:-
'Type your full address here'

When a user click on either field I want to clear any DEFAULT values that
are there making it ready for typing in.
When a user goes off either entry then I want to reinsert the DEFAULT value
if the entry remains null.

The above is just a simple example, my actual form is much more complicated
but I need to get my basic method right.

I am using the onfocus and onblur (see below) however my problem seems to be
in transfering the appropriate text field name to the function so that it
can modify the appropriate text field value ie either the name entry or the
address entry.

I have been able to do this with a seperate function for each field but want
to avoid this if I can.



   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


   <html>
   <head><title>HTML Template</title>
   <SCRIPT type="text/javascript">
   <!--

   function showvalue(entryname, entryvalue) {
    if (document.formname.entryname.value=="") {
     document.formname.entryname.value = entryvalue;
    }
   }

   function clearvalue(entryname, entryvalue) {
    if (document.formname.entryname.value == entryvalue) {
     document.formname.entryname.value="";
    }
   }

   // -->
   </SCRIPT>

   </head>
   <body bgcolor="#d0d0d0">
   <form name= formname action="http://yourcgiscript" method="post">
      <td><input type="text" name="custname" size="40" maxlength="80"
value="Type your full name here" onfocus=" clearvalue('custname','Type your
full name here');" onblur="showvalue('custname','Type your full name
here');"></td>
   </form>


   </body>
   </html>

Mant Thanks
Peter Newton

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA