User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,598 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,454 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 9453 | Replies: 13 | Solved
Reply
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: ONCLICK or HREF ?

  #11  
Sep 11th, 2007
If all the functions are equal with equal parameters, or equal ( or derivable ) functions where the parameters can be easily derived programatically per link, i.e. via setting some dummy property on the link and using it to generate or lookup the function parameters. Otherwise I can invisage an equally huge JS file... Plus, it would take some noticable, although not restrictive, post-load time to dynamically set the onload property for 6000 links..
Plato forgot the nullahedron..
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: ONCLICK or HREF ?

  #12  
Sep 11th, 2007
But in return of all this you get flexibility, the ability to change the logic without sifting through 6000 lines of your markup. Plus the load times would be less than or at the most equal to the time taken to set onclick on 6000 links by hardcoding them.

I guess this is one of those choices the OP would have to make based on his requirements.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: ONCLICK or HREF ?

  #13  
Sep 11th, 2007
>>I guess this is one of those choices the OP would have to make based on his requirements.

Pretty much.

>> But in return of all this you get flexibility, the ability to change the logic without sifting through 6000 lines of your markup. Plus the load times would be less than or at the most equal to the time taken to set onclick on 6000 links by hardcoding them.

I would debate that using JS to generate onclick handlers could save much on download time and configurabilty unless the functions and their parameters can be derived automatically with a minimum of link-specific information hardcoded anywhere in either the JS or HTML. i.e, for extreme example cases:

( hardcoded )
<a href="#" onclick="return sf('data01')"/>
= association between a's and click handlers is hardest, function name can't be changed easily, most flexible; because different functions can be called.

( changing 'c' classed 'a' elements to call an onclick function with a parameter equal to the a's id )
<a href="#" class="c" id="data01"/>
=association between a's and click handlers is medium, function name can be changed in JS, but id's have to be changed in HTML and function name can't be changed ( unless more than one class is used ), there is a noteable decrease in HTML size, but at a runtime cost compared to hardcoding. Small JS file also. Might be optimum, might not. Especially when considering that you can't legally put all characters in an 'id' attribute.. perhaps would be better to use id's as a lookup into a collection/dictionary, but then the size of the JS + HTML exceeds the size of the hardcoded HTML.

( changing 'c' classed 'a' elements to call an onclick function with a parameter pulled from an array , based on the order of the classed a's ( very messy ) )
in JS: link_data[0] = 'data01';
...
in HTML:<a href="#" class="c"/>

=association between a's and click handlers is weak, but highly confusing to change anything. Very little benefit in the smaller HTML, because the JS becomes massive. Not recommended.

Of course... if your some_func( ) really takes no parameters, and is always the same call, ( aside from the obvious question; why have 6000 of them?? ) generating the onclick handler from JS will always save alot of download bandwidth..
Last edited by MattEvans : Sep 11th, 2007 at 5:29 pm.
Plato forgot the nullahedron..
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: ONCLICK or HREF ?

  #14  
Sep 12th, 2007
thanks all for your replies.

i have tested both methods and there is very little load time difference between each case. onclick is generally faster but i find myself having to add the
element.href = 'javascsript:void(0)';
anyway to stop to postback

BUT

after some soul searching found this why not to use href="javascript"

and i qoute
eventually coming across a post on Microsoft’s Web site. It strongly suggested not using javascript:; in the href… ever.

this pretty much summed up what i have got to do. Considering this web app is built for IE only on a local intranet i have tried the method suggested above to append the ONCLICK with return false; and have had no troubles.

dont ask me why IE only, suffice to say the companies i am writing for are local councils and all have stressed they will never use any other browser except IE (which means they will never use a decent browser) but thanks again to all who commented
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC