Javascript syntax in html attributes

This is a discussion on "Javascript syntax in html attributes" within the JavaScript Forum section. This forum, and the thread "Javascript syntax in html attributes are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 9th, 2007, 18:03
New Member
Join Date: Aug 2007
Location: Berkeley, CA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Javascript syntax in html attributes

I am trying to understand some existing script and came across the following application of javascript in html attributes in an <a> tag. It was generated by php so it might not be the most orthodox javascript.

Code: Select all
onmouseover="window.status='View this entry'; show(event, 'eventinfo-224-5'); return true;" onmouseout="window.status=''; hide('eventinfo-224-5'); return true;"
I assume what is going on here is the same as the following javascript (show and hide being pre-defined functions):

Code: Select all
window.status='View this entry';
show(event, 'eventinfo-224-5');
return true;
and:

Code: Select all
onmouseout=window.status='';
hide('eventinfo-224-5');
return true;
Any comments on this way of including javascript scripts? Can one include scripts in any attribute in this manner? Is there no need for <script> tags? Other comments?

Thanks,

--Kenoli

Last edited by karinne; Sep 10th, 2007 at 13:17. Reason: Please use [ code ]...[ /code ] tags when displaying code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 9th, 2007, 21:00
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript syntax in html attributes

Quote:
Originally Posted by kenoli View Post
Other comments?
I put all my javascript, including event handlers, in the external JS file. It makes for easier code management.

If you weave your javascript into your HTML, then you can have a real headache when you decide to change those event handlers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 9th, 2007, 21:36
New Member
Join Date: Aug 2007
Location: Berkeley, CA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript syntax in html attributes

Yes, great. I think I've got it figured out. I think I was working from more recent incarnations of javascript and thrown a bit by "old style" coding.

Thanks,

--Kenoli
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 9th, 2007, 21:40
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript syntax in html attributes

Check out this article, which describes how to move event handlers out of HTML and into JS: http://www.digital-web.com/articles/...d_structure_2/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 10th, 2007, 13:49
New Member
Join Date: Aug 2007
Location: Berkeley, CA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript syntax in html attributes

Thanks for the link. It is a great article and I have read it. It was partially being aware of his admonitions on event handling that I got thrown off by the code I found.

I also have his book and find it amazing in how it goes deeper where useful for practical coding and puts the less useful stuff in perspective. So much better than books that seem more focused on a formal presentation of javascript over bringing the readers attention to those things that really impact practical use. Just because something is subtle doesn't mean it doesn't need attention if it has a real world impact. I wish someone would write a book on php like this.

Didn't mean to launch into a review, but couldn't help myself.

--Kenoli
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
attribute, mouseout, mouseover

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-Quote in Javascript/html help Manz16 JavaScript Forum 0 Apr 11th, 2008 20:11
HTML/CSS/Javascript custom scrollbar Voodoochilli Web Page Design 10 Jun 25th, 2007 22:09
Web Developer - CSS, JavaScript, HTML - Cambridge Web JobBot Job Opportunities 0 Oct 18th, 2006 14:03
Using PHP, Javascript and HTML all in one audioelite PHP Forum 7 Oct 13th, 2006 23:31


All times are GMT. The time now is 07:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42