By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,565 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

How to get the object that the client click?

P: n/a
At the old method, I place onFocus() event of all the tags like this:
<input id="input1" type="text" onFocus="func(this)">
to get the source (sender) of object.
But I think this is not a good design style for some case,
for example, I have fifty inputs in a HTML and half of it should run a
function when focus.

How to write this task better?

Jul 14 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
How to write this task better?
Depends on what you want. If each input element has its own type of
handling, then the best option is what you describe, if its the same
handler you could use a loop:

// define the generic event handler
function myEventHandler() {
this.value = 'I have focus';

// get all input elements
inputs = document.getElementsByTagName("input");

// add the event handler to each of them.
for (i = 0; i < inputs.length; i++) {
inputs[i].onfocus = myEventHandler;

Something like that. You can even decide in the loop whether or not this
input element should have an event handler, and if so, which one.

Jul 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.