/    Sign up×
Community /Pin to ProfileBookmark

Javascript Chrome Help

I have some javascript code that when the person tabs from field to field it calls a javascript function that calculates a total and then updates a field (which is disabled so users can type) on the form to display the proper total. It works fine in IE. But the it does not work in chrome or firefox? Any ideas? The last line that updates the total field in the form is frm.totalbill.value = tot;

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 07.2010 — Guessing the referencing is incorrect, use [COLOR="Green"]document.[I]formName.fieldName[/I].value[/COLOR]

Showing your code would be more helpful.
Copy linkTweet thisAlerts:
@dadressauthorNov 07.2010 — Thats not it as in the beginning of the function I have...

frm = document.myform;

only then am i doing...


frm.totalbill.value = tot;
Copy linkTweet thisAlerts:
@FangNov 07.2010 — Showing your code would be more helpful.
Copy linkTweet thisAlerts:
@dadressauthorNov 07.2010 — function calculatetotal()

{

var t;

var ac;

var shipping = 0;

frm = document.frmmyform;

var x=document.getElementById("damount");
var selectedIndex = GetSelectedIndex(x.name);

if ((selectedIndex == 3 || selectedIndex == 4) && !frm.shipping[1].checked)
shipping = 5;

if (selectedIndex > -1)
t = frm.damount[selectedIndex].value
else
t = 0;

ac = parseFloat(frm.addcookbooks.value);
if (ac != parseFloat(ac))
{
ac= 0;
}
else
{
if (!frm.shipping[1].checked)
ac = ac * (18 + 5);
else
ac = ac * 18;
}

ac2 = parseFloat(frm.addcookbooks2.value);
if (ac2 != parseFloat(ac2))
{
ac2= 0;
}
else
{
if (!frm.shipping[1].checked)
ac2 = ac2 * (18 + 5);
else
ac2 = ac2 * 18;
}


var tot = parseFloat(t) + parseFloat(ac) + parseFloat(ac2) + shipping;
frm.totalbill.value = tot;

}
Copy linkTweet thisAlerts:
@FangNov 07.2010 — Does the select "damount" have [I]id[/I] and [I]name[/I]?

Are there any errors in the Console?
Copy linkTweet thisAlerts:
@dadressauthorNov 07.2010 — there is no id in field just name...

no errors it just does not show the field value the rest of the javascript works fine
Copy linkTweet thisAlerts:
@FangNov 07.2010 — This is wrong then[CODE]var x=[COLOR="Red"]document.getElementById("damount");[/COLOR]
var selectedIndex = GetSelectedIndex(x.name);[/CODE]

use[CODE]var selectedIndex = GetSelectedIndex('damount');[/CODE]
Copy linkTweet thisAlerts:
@dadressauthorNov 07.2010 — Thanks so much!
×

Success!

Help @dadress 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...