Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2003, 05:59 PM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Example 4 Ch 5 -Begining JavaScript

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


 
Old November 26th, 2003, 06:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old November 27th, 2003, 03:12 AM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>


 
Old November 27th, 2003, 04:31 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
 
Old November 27th, 2003, 04:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

This will work:
Code:
<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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
begining c# benjamin C# 4 March 3rd, 2010 08:37 AM
does not work register.php in ch 11 begining php5 tanvir_math BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 February 7th, 2007 05:03 PM
Begining JavaServerPages varun_java JSP Basics 0 April 11th, 2005 09:51 AM
Beg. Javascript 2nd Ed Ch 13: IE_NN_Menus.htm mcange HTML Code Clinic 0 March 15th, 2005 05:54 PM
Begining C# pappubhai Wrox Book Feedback 0 July 20th, 2003 12:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.