|
-
Feb 7th, 2002, 05:46 PM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 7th, 2002, 06:16 PM
#2
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|