0

I'd like to define my own onblur event for all text boxes in an application so that I can strip all high ascii values, so I wrote a script that runs on an asp.net master page that runs per page load, overriding all text box / area onblur events, and storing a copy of the old event.

The new event then called the old event so it wouldn't break existing events across the forms.

It worked fine until a page defined an onblur like: onblur="func(this)" When the original event fires the 'this' point doesn't seem to point to the sender control any longer.

Pastebin link with 2 simple examples

So would anyone be able to point me towards a better way to accomplish this?

Thanks!

1 Answer 1

1

To call a function dynamically while controlling the value of this, use func.apply instead of a standard call. For example instead of

myStoredFunc(arg1, arg2)

use :

myStoredFunc.apply(this, arguments);

This way the value of the this variable will be correctly passed to the called function, thanks to apply's first argument. The second argument allows you to specify the parameter values (here I pass all the current function's arguments to the called function).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.