OZONE Asylum
Forums
DHTML/Javascript
How do I code Javascript unobstru..unostrub...unobs..uno..u n o b t r u s i v e l y
This page's ID:
30385
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hi guys, I've recently after having coded for a while have started getting on the bandwagon of unobtrusive javascripting as it seems cleaner and really hassle free to have your javascript separate from your html and php code. I've read up on it in some articles like this one: http://www.onlinetools.org/articles/unobtrusivejavascript/ However I'm at a standstill with respect to actually implementing it as how I need it. Like let me show you what I mean. Lets say I'm creating an address book - Php MySQL AJaxified. I normally create the individual rows in a for loop for each entry I retrieve form teh db as so: [code]string = ''; for($i=0;$i<$rs;$i++) string .= _createRow($rs[$i]); function _createRow($data) { $xhtml = '<div id="rowid'.$data['id'].'" >'.$data['name'].' - Contact Details:'.$data['contact'].'</div>'; $xhtml .= '<a href="#" onclick="deleteContact('.$data['id'].')">delete</a>'; return $xhtml; } [/code] Now from what I know in unobstrusive javascripting you assign functions to dom elements on page load instead of populating each and every required html item with onclick and onload handlers. This seems ok but when your contentitself is dynamic like in teh example above in a page being created by a php script where likewise you would be passing variables tofunctions based upon teh element you interact with. How do you implement it unobtrusively. I.e in the example above the deleteContact javascript function is programmatically added to the anchor link with the contact id being passed in as a variable. If I were to code javascript unobtrusively how woudl I be able to handle this kind of situation where I need to like pass numerous variables of sometimes differing natures to JS functions. Any help would be appreciated - I really would like to start coding the RIGHT WAY!
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »