homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

javascript error
Calling a function from <a> tag.

 9:15 pm on Aug 2, 2002 (gmt 0)

Hello WW. I'm working on what should be an easy script. But not for me of course. :( What I want it to do is send item info to the function which contains the long paypal link so I don't have to put it in each item "buy" link.
Here it is:

<script language="JavaScript">
function order(item,desc,cost)
var sOrder = "https://www.paypal.com/cart/add=1&business=Myidnumber&item_name=" + desc + "&item_number=" + item + "&amount=" + cost + "";

<a class="red" href="javascript:order(item#,item description,item price">Buy now!</a>

Could someone tell me what I'm doing wrong here? I've been cramming CSS and forgot some of the javascript I had learned. Thanks.



 9:49 pm on Aug 2, 2002 (gmt 0)

Can't see anything obvious (other than your # in the a href :) )

Your best bet is to put the site in Netscape, click on the link and then type:


in the address bar. This will show you all the errors in JavaScript and the line they appear on. Then post back on here and I will see if I can help any further. Or you may be able to solve it from the description it gives you.


 10:41 pm on Aug 2, 2002 (gmt 0)

Is there really a line break in the stuff going into sOrder?

How are you loading the parms passed to order(). Why not try this first javascript: order('parm1','parm2','parm3') then if that works load up the real stuff?

BTW, I think language=javascript is deprecated, but I wouldn't swear to it.


 11:44 pm on Aug 2, 2002 (gmt 0)

You're missing a close parenthesis in the link and single quotes around your values:

<a class="red" href="javascript:order('item','item description','item price')">Buy now!</a>

Note: had to leave a space after the colon 'cause I was triggering a "shocked" smilie!

Tedster's edit: You can turn off smilies as needed - checkbox is two up from the submit button

[edited by: tedster at 12:12 am (utc) on Aug. 3, 2002]


 2:10 am on Aug 3, 2002 (gmt 0)

Thank you, toadhall. Now I feel stupid, but I already knew I would with that question. It's hard to spot those syntax errors sometimes. It's working now. Thanks!

Oh yeah, I had to edit my post(turned off smileys), too. It was funny when I first saw it, though. :o


 7:09 am on Aug 3, 2002 (gmt 0)

Is there really a line break in the stuff going into sOrder?

JavaScript can be tricky when it comes to line breaks.

The easy rule is: except in a few specific cases (e.g. in for statements and literal strings) a semicolon will always end a statement.

Since JavaScript is intended to be delivered over a network, a line-break will also terminate a statement only if the code to the left of the line break is a complete statement. This means that the following code is one statement:

var x = a +

...because var x=a+ is not a complete statement. The following, however, is two statements, and the second one gives an error:

var x = a
+ b;

This is JavaScript trying to give you a compromise between readability and efficiency. Sometimes the two considerations come into conflict.


 10:18 pm on Aug 3, 2002 (gmt 0)

Please also note that

<script language="JavaScript">

needs to be:

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

if you also want the page to validate.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved