Topic: obtrusive JS?

Hi everyone,

I would like to hear from some experieneced developers their thoughts on "obtrusive" js.. What is the importance of having non-obtrusive code? What is the real benefit? If a site requires javascript for it to function, then is there really a reason to worry about obtrusive code?

I have been working on an app which uses prototype and scriptaculous, and my app is very javascript intensive, and I often use a lot of onchange, onclick in my views.

The main reason I do this is because I guess it's the way I learned to do it in the first place.. But secondly, there is definitely an element of convenience to doing things the way I have done them. For example, I may do something with a select tag like:

:onchange => remote_function(:url => @some_var(@some_params), :method => :get)

Which if I understand correctly, to do "unobtrusively", would require that I have JS code execute when the dom has loaded, that stores my ruby parameters as global variables in javascript... Then I would have to have an observer check when that form input is changed, and have a function create a new ajax request with all those parameters, including worrying about authenticity tokens-- which the way I currently have things set up I don't even have to think about.

Another thing that makes me question if doing things unobtrusively will serve me is that right now, my html and it's JS functions are linked together in a very visual way... I see:

<%- search_button = submit_tag '', :id => 'search_magnifying_glass', :onclick => "elementToggle('spinner', 'listing');" -%>

and I immediately know that submit button is going to call my toggle function. However, if there was no onclick there, I would have to go to my external JS file, and look up an ID called search_magnifying_glass and see what it's doing. Which also seems less convenient to me.

So, I would love to hear what you guys think regarding this, because I am interested in being the best programmer than I can be, and I am not necessarily attached to my ways-- I just need to understand why something should be done differently if it is A) working, and B) less of a headache... And I should add: C) completely indifferent from a user's perspective (since they are going to be required to use JS for the site to function anyway).

Thank you very much.

-Patrick