Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onblur question

Status
Not open for further replies.

bmcc

Technical User
May 31, 2002
10
US
I'm using onBlur() to validate a field in a form.(following code, btw chkdup() is a Javascript function)

<form name=&quot;survey&quot; method=&quot;post&quot; action=&quot;Confirm.asp&quot;>
<input type=&quot;text&quot; name=&quot;a&quot; onBlur=chkdup()>
<input type=&quot;text&quot; name=&quot;b&quot;>
<input type=&quot;submit&quot; name=&quot;sub&quot; value=&quot;sub&quot;>

Here is my question: how do i find out which one triggered the onBlur(), it can be by clicking on field b or by clicking on the submit button. Many Thanks.
 
hi bmcc,

technically, neither of those are triggering the function. onblur fires whenever the element loses focus - clicking anywhere outside of the element will fire the event, regardless of whether the other two elements were clicked.

there's probably another way - why do you want to determine what received focus?
=========================================================
if (!succeed) try();
-jeff
 
assuming that you want the function called by onblur to know the name of the element clicked on to cause the onblur, i'm not sure if this can be done. part of the problem is the order of events. the onblur event occurs before the onfocus event. why do you need to know? depending on what you're trying to do, there may be a work-around.

glenn
 
As stated before you cannot do this.

The only options you would have that I can see are to determine if the Enter key or Tab is hit with the OnKeyPress event and then capturing some value based on those events for your use. I'm not sure if there is a mouse lick event in javascript. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
In my code, &quot;chkdup()&quot; will do the followings: open a child window, validate user input against database data, then close itself (child window).

If onblur is triggered by pushing Submit button, then immediately after the validation (as above)
, it should invoke the Confirm.asp (if validation is successful).

However, if onblur is caused by going to any other field, then validation is enough and I do not
need to invoke the Confirm.asp.

This is why I need to know which field triggered the onblur.

If this is not doable, is there any way to get around ?

Many Thanks.
 
Ok. Just add this to the submit button:

onClick=&quot;invoke_confirm.asp_function()&quot;

That way, since onBlur is executed first, it will do the chkdup() then the onClick in the submit button will work when the submit button is clicked.

Rick It's a pleasure to know that I've helped you. If I have,
please click the link below to let me know. :)
 
so what you're really asking for is how to stop the form from being submitted after the validation is returned if a error was found?

if that's the case then we need to see the fundtion but returning false on finding a error should be all you need and focus on the form element. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top