TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-21-2009, 10:04 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default JS in a href.......

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?

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

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



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

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


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



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();
allworknoplay is offline  
Reply With Quote
Old 04-21-2009, 10:47 PM   #2 (permalink)
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
Old 04-21-2009, 11:04 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Kalle View Post
This executes a javascript event when the link
No because the "javascript" protocol (which isn't actually a protocol) has a special meaning to the browsers.



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).

Great thanks, that clears it up.

So the browsers just "naturally" understand what to do when you have "a href=javascript:whatever()".....




I hope DOM isn't that hard, I'll be jumping on that this weekend....
allworknoplay is offline  
Reply With Quote
Old 04-22-2009, 03:44 PM   #4 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

DOM is pretty straigth forward once you gasped the basic of it, you will find the MSDN Library more than excellent for DOM references:
http://msdn.microsoft.com/en-us/library/aa155133.aspx

-> HTML & DHTML (Dynamic HTML)

When you view the CSS reference on MSDN you will also be able to see the scripting names for that style like:
HTML Code:
<input type="button" onclick="this.backgroundColor = '#000000';" value=" Click me " />
same goes for the HTML reference, you will see which events and actions that apply to each tag.
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 04-22-2009, 03:46 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Kalle View Post
DOM is pretty straigth forward once you gasped the basic of it, you will find the MSDN Library more than excellent for DOM references:
http://msdn.microsoft.com/en-us/library/aa155133.aspx

-> HTML & DHTML (Dynamic HTML)

When you view the CSS reference on MSDN you will also be able to see the scripting names for that style like:
HTML Code:
<input type="button" onclick="this.backgroundColor = '#000000';" value=" Click me " />
same goes for the HTML reference, you will see which events and actions that apply to each tag.

What is the difference between DHTML and Ajax?
allworknoplay is offline  
Reply With Quote
Old 04-22-2009, 06:10 PM   #6 (permalink)
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
What is the difference between DHTML and Ajax?
DHTML is an rather old term for HTML that may change during browsing, for example an event that occurs when you click a button which may spawn something. But in theory yes then AJAX can be classified as DHTML.
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
allworknoplay (04-22-2009)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB 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
How to navigate through pages automatically without href links shankar General 1 04-20-2009 04:00 PM
help me with this href thing meshi General 3 10-17-2007 01:39 PM


All times are GMT. The time now is 12:53 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design