/    Sign up×
Community /Pin to ProfileBookmark

JS & FF duke it out!

Arg. Having serious issues here, and looking for ideas. Probably something simple. This is a registration page for a yearly event. The custom JS I created to talk to Paypal works in IE, break in FF. It seems that the functions are not getting defined for some reason, among other errors.

Here is the abbreviated HTML for the form (I left out design elements, etc. To see the form in ‘action’, send me a PM and I will send you the link:

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>stlbx 05 registration</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<script src=”includes/register.js” type=”text/javascript”></script>
<link href=”includes/stlbx2005.css” rel=”stylesheet” type=”text/css” />
</head>
<body>
<form action=”” method=”post” name=”info” class=”bodyText”>
<table width=”100%” border=”0″ cellpadding=”10″>
<tr>
<td width=”32%” align=”right”>First Name </td>
<td width=”68%” align=”left” valign=”middle”>
<input name=”firstname” type=”text” id=”firstname” size=”30″ />
</td>
</tr>
<tr>
<td align=”right”>Last Name</td>
<td align=”left” valign=”middle”>
<input name=”lastname” type=”text” id=”lastname2″ size=”30″ />
</td>
</tr>
<tr>
<td align=”right”>Address 1 </td>
<td align=”left” valign=”middle”>
<input name=”address1″ type=”text” id=”address12″ size=”30″ />
</td>
</tr>
<tr>
<td align=”right”>Address 2 </td>
<td align=”left” valign=”middle”>
<input name=”address2″ type=”text” id=”address22″ size=”30″ />
</td>
</tr>
<tr>
<td align=”right”>City</td>
<td align=”left” valign=”middle”>
<input name=”city” type=”text” id=”city2″ />
</td>
</tr>
<tr>
<td align=”right”>State</td>
<td align=”left” valign=”middle”>
<input name=”state” type=”text” id=”state2″ size=”6″ maxlength=”2″ />
</td>
</tr>
<tr>
<td align=”right”>Zip</td>
<td align=”left” valign=”middle”>
<input name=”zip” type=”text” id=”zip2″ size=”15″ />
</td>
</tr>
<tr>
<td align=”right”>Email</td>
<td align=”left” valign=”middle”>
<input name=”email” type=”text” id=”email2″ size=”30″ />
</td>
</tr>
<tr>
<td align=”right”>Day Phone </td>
<td align=”left” valign=”middle”>
<input name=”dayphone” type=”text” id=”dayphone2″ />
</td>
</tr>
<tr>
<td align=”right”>Night Phone </td>
<td align=”left” valign=”middle”>
<input name=”nightphone” type=”text” id=”nightphone2″ />
</td>
</tr>
</table>
<p>Scroll to the package deal you would liek to purchase, select any appropriate options, then click Continue to go on to the PayPal payment center. </p>
</form>
<p class=”bodyText”>
<input type=”hidden” name=”package” value=”Package%20A” />
<input type=”hidden” name=”packcost” value=”74″ />
<input type=”checkbox” name=”cruise” value=”true” checked disabled />
<a href=”thursday.html” target=”_blank”>Cruise</a><br />
<input type=”checkbox” name=”workshop” value=”true” checked disabled />
<a href=”saturday.html#workshop” target=”_blank”>Workshop</a><br />
<input type=”checkbox” name=”tshirt” value=”true” checked disabled />
<a href=”tshirt.html” target=”_blank”>T-shirt</a>
<select name=”style”>
<option selected>Select a Style</option>
<option value=”standard male”>Standard Male T</option>
<option value=”female baby doll”>Female Baby Doll</option>
</select>
<select name=”size”>
<option selected>Select a Size</option>
<option value=”small”>Small</option>
<option value=”medium”>Medium</option>
<option value=”large”>Large</option>
<option value=”x-large”>X-Large</option>
</select>
<br />
Your current total is
<input type=”text” name=”total” size=”10″ value=”$99.00″ disabled />
<br />
<input type=”submit” name=”Submit” value=”Continue” onclick=”registerPaypal(this.form); return false” />
(AND SO ON FOR TWO OTHER IDENTICALLY CODED SECTIONS…)
</span></p>
</form>
</body>
</html>
[/code]

And the JS:

[code]
function registerPaypal(form) {
var paypalURL=”https://www.paypal.com/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&[email protected]
&return=http%3A//www.stlbx.com/thankyou.html&cancel_return=http%3A//www.stlbx.com/cancel.html&image_url=
http%3A//www.gatewaylindyhop.com/images/stlbx-banner.gif&first_name=”+document.forms[0].firstname.value+”&last_name=
“+document.forms[0].lastname.value+”&address1=”+document.forms[0].address1.value+”&address2=”+
document.forms[0].address2.value+”&city=”+document.forms[0].city.value+”&state=”+document.forms[0].state.value+”&zip=
“+document.forms[0].zip.value+”&day_phone_a=”+document.forms[0].dayphone.value+”&night_phone_a=”+
document.forms[0].nightphone.value+”&item_name=Saint%20Louis%20Lindy%20Blues%20Exchange%202003”
var restofURL
if (form.tshirt.checked) {
if (form.style.options[0].selected ¦¦ form.size.options[0].selected) {alert (“Please select a style and size”); return false}
else {restofURL= “%20” + form.package.value + “&amount=” + form.total.value + “&item_number=” + form.package.value + “&on0=T-Shirt&os0=” + form.size.options.value + “,%20” + form.style.options.value + “,%20” + “&on1=Options&os1=workshop-” + form.workshop.checked + “%20cruise-” + form.cruise.checked
location.href=(paypalURL + restofURL); return false
}
}
else {restofURL= “%20” + form.package.value + “&amount=” + form.total.value + “&item_number=” + form.package.value + “&on0=T-Shirt&os0=NONE,%20NA&on1=Options&os1=workshop-” + form.workshop.checked + “%20cruise-” + form.cruise.checked
location.href=(paypalURL + restofURL); return false}
}
function formatCurrency(num) {
num = num.toString().replace(/$¦,/g,”);
if(isNaN(num))
num = “0”;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = “0” + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+’,’+
num.substring(num.length-(4*i+3));
return (((sign)?”:’-‘) + ‘$’ + num + ‘.’ + cents);
}
function modifyTotal(form) {
var initialCost = parseFloat(form.packcost.value)
var addOn = 0.00
var workingTotal = initialCost
var cruise = 12.50
var workshop = 12.50
var tshirt = 15.00
if (form.tshirt.checked) {
addOn = tshirt
}
workingTotal = workingTotal + addOn
addOn = 0
if (form.cruise.checked) {
addOn = cruise
}
workingTotal = workingTotal + addOn
addOn = 0.00
if (form.workshop.checked) {
addOn = workshop
}
workingTotal = workingTotal + addOn
addOn = 0.00
workingTotal = formatCurrency(workingTotal)
addOn = 0.00
form.total.value = workingTotal
}
[/code]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jul 20.2005 — Is the JavaScript Console window showing any errors?

Eric
Copy linkTweet thisAlerts:
@thecheetaauthorJul 20.2005 — Sorry - yes, there are:

Error: missing name after . operator

Source File: http://www.stlbx.com/2005/includes/register.js

Line: 6, Column: 32

Source Code:

else {restofURL= "%20" + form.package.value + "&amount=" + form.total.value + "&item_number=" + form.package.value + "&on0=T-Shirt&os0=" + form.size.options.value + ",%20" + form.style.options.value + ",%20" + "&on1=Options&os1=workshop-" + form.worksho


The little arrow points under the "a" in the first 'form.package.value'

If I try to do anything that invokes a function on the page (such as clicking in a checkbox, which changes the price, or submitting the form, which checks to see if a t-shirt size/sex has been selected, and if not, an alert pops up, and if so, the form information is processed and sent to PayPal), I get either:

Error: modifyTotal is not defined

or

Error: registerPaypal is not defined


Which is weird, because, they ARE defined, and the JS file is clearly being read, because I am getting the first error. Arg....
Copy linkTweet thisAlerts:
@A1ien51Jul 20.2005 — first off I would not use form, rename that to somehing else like oForm.

Eric
Copy linkTweet thisAlerts:
@KorJul 20.2005 — I don't get the sense of the variable paypalURL... Why not simply HTML submit the form to an action? The submit method will automatically add the names and values and send/get them to/from the server's application...
Copy linkTweet thisAlerts:
@thecheetaauthorJul 20.2005 — Well, the page is made of of four forms... the first is the applicant's general information. Then, they select which event "package" they want. There are three different choices, packages a,b, and c. Each of these packages has options (they are the same options). Package A is all-inclusive. B & C have a'la carte items. One of these items, a t-shirt, require the applicant to pick a size before moving on.

I probably have designed this whole thing assbackwards. I am interested in your input as to how it may be done more efficiently. You can see what I am getting at if you visit http://www.stlbx.com/2005/register.htm (note... not trying to advertise anything here, I realize not many in this community would be interested in a dance event...)
Copy linkTweet thisAlerts:
@ExuroJul 20.2005 — I think I finally figured it out! The problem is that [FONT=Courier New]package[/FONT] is a reserved-word in Mozilla/Firefox. So, to fix your page, all you have to do is rename that form fields to something else. Something like [FONT=Courier New]dancePackage[/FONT] should work just fine. For future reference, here is a list of reserved-words you should avoid using as identifiers in your code:

[url=http://www.mozilla.org/js/language/js20/core/lexer.html#reserved-word]http://www.mozilla.org/js/language/js20/core/lexer.html#reserved-word[/url]
Copy linkTweet thisAlerts:
@felgallJul 20.2005 — package is not a reserved word in Javascript. It is a predefined object used by LiveConnect to allow communications between Javascript and Java. The reason that IE doesn't complain is that IE doesn't support LiveConnect.
Copy linkTweet thisAlerts:
@ExuroJul 20.2005 — package is not a reserved word in Javascript. It is a predefined object used by LiveConnect to allow communications between Javascript and Java. The reason that IE doesn't complain is that IE doesn't support LiveConnect.[/QUOTE]No, [FONT=Courier New]package[/FONT] is [i]definitely[/i] a reserved word in JavaScript. Check the [url=http://www.mozilla.org/js/language/index.html]ECMA spec[/url] or any reserved-word list you want and it'll be there. The [FONT=Courier New]Packages[/FONT] object is part of LiveConnect I think, but that's not what we were talking about here. The reason IE doesn't throw an error is because it's parser is very lax and either doesn't include the [FONT=Courier New]packages[/FONT] keyword specified in the ECMAScript standard, or just doesn't care if you overwrite it.
Copy linkTweet thisAlerts:
@Orc_ScorcherJul 20.2005 — FWIW, all keywords which are used in Java but not in JavaScript will not cause errors in Firefox 1.1 any more: see [URL=https://bugzilla.mozilla.org/show_bug.cgi?id=240317]bug 240317[/URL].
×

Success!

Help @thecheeta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...