|
Subject:
|
Example 4 Ch 5 -Begining JavaScript
|
|
Posted By:
|
flyn
|
Post Date:
|
11/26/2003 4:59:09 PM
|
<SCRIPT LANGUAGE=”JavaScript”>
function linkSomePage_onClick() { alert(‘This link is going nowhere’); return false; } I cannot find an error, but this code gives one every time, HELP...
</SCRIPT>
<A HREF=”http://flynpenoyer.com/JavaScript/index2.html” NAME=”linkSomePage”> Click Me </A>
<SCRIPT LANGUAGE=”JavaScript”>
window.document.links[0].onclick = linkSomePage_onclick;
</SCRIPT>
|
|
Reply By:
|
Imar
|
Reply Date:
|
11/26/2003 5:40:56 PM
|
Hi there,
If this is a direct copy and paste of your code, I think it's the quotes.
function linkSomePage_onClick() { alert(‘This link is going nowhere’); return false; }
should be:
function linkSomePage_onClick() { alert('This link is going nowhere'); return false; }
Are you using Word for coding? ;-) Word replaces quotes like this....
Also, JavaScript is case sensitive; you call linkSomePage_onclick, while the method is called linkSomePage_onClick (Capital C)
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
flyn
|
Reply Date:
|
11/27/2003 2:12:49 AM
|
Could you please explain the quotes thing a bit more...
I have been using word.
I redid it in Notepad with quotes and caped the C, and now I get no error and no alert box??
<SCRIPT LANGUAGE="JavaScript">
function linkSomePage_onClick() { alert('This link is going nowhere'); return false; } </SCRIPT>
<A HREF="http://flynpenoyer.com/JavaScript/index2.html" NAME="linkSomePage"> Click Me </A>
<SCRIPT LANGUAGE="JavaScript">
window.document.links[0].onClick = linkSomePage_onClick;
</SCRIPT>
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
11/27/2003 3:31:38 AM
|
As Imar said JavaScript is case sensitive, your function name does not match the name you assign. As to using Word for code editing, forget it. It messes araound too much with your input, in this instance by giving smart quotes instead of apostrophes. Use Notepad or a proper programmers editor such as EditPlus.
--
Joe
|
|
Reply By:
|
Imar
|
Reply Date:
|
11/27/2003 3:35:45 AM
|
Hi there,
This will work:<html>
<head>
<script language="Javascript">
function linkSomePage_onClick()
{
alert('This link is going nowhere');
return false;
}
</script>
</head>
<body>
<a id="idTest" href="http://flynpenoyer.com/Javascript/index2.html" name="linkSomePage">Click Me</a>
<script language="Javascript">
document.links[0].onclick = linkSomePage_onClick;
</script>
</body>
</html>All I really changed was the onClick to onclick (case sensitive).
Word has a feature called Auto Correct that replaces straight quotes with "smart quotes" (yeah, right). If you want to code in Word, you should disable this feature. Choose Tools | AutoCorrect options" and then on the "AutoFormat as You Type" and "AutoFormat" tabs disable this feature.
Personally, I wouldn't recommend Word for coding. It's a nice Word processor, but not a good coding environment. If you want something text based, try Textpad, or some other freeware / shareware editors.
Alternatively, you can try an IDE, like Dreamweaver MX or Visual Studio for your coding. Those programs are not cheap, but worth their money, IMO.
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|