Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
markifornia

Chapter 8: Event Handling

Recommended Posts

This chapter discusses a topic on keyboard events. I have provided links to my dev website.

 

On page 284, the "change" event is added to the U.addEvent method.

 

 


U.addEvent(U.$('comments'), 'change', limitText);

 

 

http://www.sandiegowebcreative.com/text.html

 

 

On page 284, the "keyup" event is added to the U.addEvent method.

 


U.addEvent(U.$('comments'), 'keyup', limitText);


 

http://www.sandiegowebcreative.com/text2.html

 

 

I don't notice the difference between the two. I receive the same results from my browser, or I may not be noticing that which is obvious (or not as obvious?)

 

Anyone come across this?

Share this post


Link to post
Share on other sites

Good question. In this case, I have a feeling that there is no noticeable difference between the two (but I could be wrong).

I noticed that the behavior is the same even when you hold a key down.

 

I suppose, in general, I would stick with the keyboard event handlers for pressing keys and use the change event handler for things like selecting items in a select element, etc.

Share this post


Link to post
Share on other sites

Thanks Hartley, could very well be the reason why on page 287, both events are passed to the function.

 

 


 
U.addEvent(U.$('comments'), 'keyup', limitText);
U.addEvent(U.$('comments'), 'change', limitText);

 

Page 288 goes into detail about accessibility with introducing a concept known as "pairing events". I guess the above is similar to the concept. 

 

 

 
<a href="somepage.html" id="link">Some Text</a>
 
// javascript:
 
addEvent(document.getElementById('link'), 'mouseover', doSomething);
addEvent(document.getElementById('link'), 'focus', doSomething);
 

 

I guess this makes some sense now. 

Share this post


Link to post
Share on other sites

I'm actually not sure what's trying to be achieved on page 287. Sorry.

I think your second example though is just an example of attaching two events to the same element, which you may sometimes want to do.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...