| javascript error Calling a function from <a> tag. |
Birdman

msg:1481300 | 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 + ""; window.open(sOrder,'cartwin','width=600,height=400,scrollbars,location,resizable,status'); } </script> <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.
|
gsx

msg:1481301 | 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: javascript: 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.
|
RossWal

msg:1481302 | 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.
|
toadhall

msg:1481303 | 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]
|
Birdman

msg:1481304 | 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
|
rewboss

msg:1481305 | 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 + b; ...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.
|
g1smd

msg:1481306 | 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.
|
|
|