Ok a comple of things wrong...first off JS arrays typically start at 0. 
You should pass objects to your function, not names, so you would
would want to pass this and you do not need to pass the form name.
Your field_text array needs to be initialized before hand too. I also
changed the array to an associative array moves faster and I think
looks nicer. Heres the reworked code:

<html>
<script>
function clearOnce2(theField) {
  var  field_text = new Array();
   field_text["ncr_number"] = "enter ncr numbers, a, b,c";
   field_text["part_num"] = "enter a part number";
   field_text["order_num"] = "enter an order number";
   if (theField.value == field_text[theField.name])
      {theField.value="";}
}

// -->
</script>

<body>
<form name="imageupload"
action="file:///Macintosh%20HD/Users/joe/work/image%20app/image_app.cfm"
method="post" enctype="multipart/form-data">

<table border="3" style="font-weight:bold" align="center">
<tr align="center">
   <td valign="middle"><span style="color:green">ncr number</span><br><br>
       <span style="color:maroon; font-size:18">OR</span><br><br><span
style="color:orange">part number and order number</span></td>
   <td valign="middle">
       <input name="ncr_number" type="text" size="25" style="color:green"
maxlength="100" title="enter ncr numbers"  VALUE="enter ncr numbers, a, b,c"
 onfocus="javascript:clearOnce2(this);">
       <br><br><span style="color:maroon; font-size:18">OR</span><br><br>
       <input name="part_num" type="text" size="15" style="color:orange"
maxlength="25" title="part number"  VALUE="enter a part number"
onfocus="javascript:clearOnce2(this);">
       <input name="order_num" type="text" size="15" style="color:orange"
maxlength="25" title="order number"  VALUE="enter an order number"
onfocus="javascript:clearOnce2(this);">
   </td>
</tr>
</table>
<input type="submit" value="upload the image files">
</form>
</body>
</html>


Notice how instead of passing the name I just pass this...this refers
to the current object (in the cases above uit would the input box). If
for some reason you wanted access to the Form object you can do
this.form or in the function theField.form. If you need mroe
explaining let me know.


Adam H

On Mon, 10 Jan 2005 09:44:44 -0600, joe zanter <[EMAIL PROTECTED]> wrote:
> Hi All,
> Took the littlun's out sledding this weekend-- grrrreat time! My daughter
> (7) had something of a hard time with the concept of having to walk up after
> each ride down. I can see her point.
> 
> I'm missing something in the code below...
> It's a script which is supposed to clear the default text in a form field,
> the first time the field is focussed on. Subsequent visits to the field have
> no effect. The first version does this, but it's in explicit form. I wanted
> to write a more general version. I know the arguments are being passed, but
> the variables, "theForm" and "theField" apparently aren't being recognized
> as I was hoping.
> 
> Here's the code. I'll pull your sled up the hill if you have a clue about
> what  I'm clueless about!
> -------
> 
> <html>
> <script type="Javascript">
> // this little script is supposed to clear the content of a field the first
> time the field is entered to remove default messages
> function clearOnce(theForm, theField) {
>    var ncr_text = "enter ncr numbers, a, b, c";
> 
> // this explicit one does work
>    if (document.imageupload.ncr_number.value == ncr_text)
>    {document.imageupload.ncr_number.value="";}
> }
> 
> function clearOnce2(theForm, theField) {
>    var field_and_form = new Array()
>    field_text[1] = "enter ncr numbers, a, b, c";
>    field_text[2] = "enter a part number";
>    field_text[3] = "enter an order number";
> 
>    for (var index = 0;index <= field_text.length; index++){
>        if (document.theForm.theField.value == field_text[index])
>        {document.theForm.theField.value="";}
>    }
> }
> 
> // -->
> </script>
> 
> <body>
> <form name="imageupload"
> action="file:///Macintosh%20HD/Users/joe/work/image%20app/image_app.cfm"
> method="post" enctype="multipart/form-data">
> 
> <table border="3" style="font-weight:bold" align="center">
> <tr align="center">
>    <td valign="middle"><span style="color:green">ncr number</span><br><br>
>        <span style="color:maroon; font-size:18">OR</span><br><br><span
> style="color:orange">part number and order number</span></td>
>    <td valign="middle">
>        <input name="ncr_number" type="text" size="25" style="color:green"
> maxlength="100" title="enter ncr numbers"  VALUE="enter ncr numbers, a, b,
> c" onfocus="javascript:clearOnce('imageupload', 'ncr_number');">
>        <br><br><span style="color:maroon; font-size:18">OR</span><br><br>
>        <input name="part_num" type="text" size="15" style="color:orange"
> maxlength="25" title="part number"  VALUE="enter a part number"
> onfocus="javascript:clearOnce2('imageupload', 'part_num');">
>        <input name="order_num" type="text" size="15" style="color:orange"
> maxlength="25" title="order number"  VALUE="enter an order number"
> onfocus="javascript:clearOnce2('imageupload', 'order_num');">
>    </td>
> </tr>
> </table>
> <input type="submit" value="upload the image files">
> </form>
> </body>
> </html>
> 
> -------
> --
> Joe Zanter
> [EMAIL PROTECTED]
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:5:141885
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/5
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:5
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.5
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to