Results 1 to 2 of 2

Thread: Which text field onFocus called the function?

  1. #1

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Which text field onFocus called the function?

    Hi,
    Question:
    Is there something that can be passed to a Javascript function that tells the function which element index called it?

    I'm doing some date/time verification with Javascript.
    DateTime2 must be after DateTime1 and DateTime3 must be after DateTime2. DateTime1 comes from a database.
    A onFocus in DateTime3 calls the function to verify that DateTime2 date is after DateTime1. Likewise an onFocus in the field after DateTime3 verifies DateTime2 and DateTime3.
    Code:
    strHtml=strHtml & "function check_isDate(day,month,year,x,what)"
    strHtml=strHtml & "{"
    strHtml=strHtml & "   if (!isDate(day,month,year))"
    strHtml=strHtml & "   {"
    strHtml=strHtml & "     alert(""Invalid "" + what);"
    strHtml=strHtml & "     document.CallInfo.elements[x-3].focus();"
    strHtml=strHtml & "   }"
    strHtml=strHtml & "}"
    Right now I'm hardcoding an element number (x in the above) in the function call.The purpose for this is so I can set the focus back to the field that contained the error.

    I hope this makes sense.

    Al.
    A computer is a tool, not a toy.

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    I think this should be fairly straightforward. Try:

    onFocus="check_isDate(day,month,year,i,this );

    In your function, you've got:
    alert(""Invalid "" + what);"

    This will perhaps return somthing like "Invalid [object]", but if you change it to something like:

    alert('"Invalid"' + what.name);

    You should get something like "Invalid" myThing, provided you also have properly named the object that's throwing the onFocus event.

    cudabean

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width