View Single Post
Old 04-21-2009, 10:47 PM   #2 (permalink)
Kalle
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
can someone explain to me fundamentally what this does?


<a href="javascript:myFunction();">

I assume that the first part "javascript" is calling
my javascript up in the header?
This executes a javascript event when the link is clicked on

Quote:
Originally Posted by allworknoplay View Post
<script type="text/javascript"></script>

And myFunction is calling a function that is within that script?
Yes

Quote:
Originally Posted by allworknoplay View Post

So hypothetically, if I did this, then it's the same philosophy?

<script type="text/whatever"></script>


<a href="whatever:myFunction();">

No because the "javascript" protocol (which isn't actually a protocol) has a special meaning to the browsers.

Quote:
Originally Posted by allworknoplay View Post
Also, why is it that when calling a function outside of the
javascript tags, you use the parenthesis "()"..

But within it, you don't? Like this...

Code:
<script type="text/javascript">

var clickCount = 0;
function documentClick(){
    document.getElementById('clicked').value = ++clickCount;
}
document.onclick = documentClick;

</script>
How come:

document.onclick = documentClick;

Doesn't use parenthesis? Shouldn't it be?

document.onclick = documentClick();
Thats because you assign a callback to the event, if you call it directly it will be the result of the "documentClick()" function, which returns null (void).
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote