Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
May 20th, 2003, 10:18 AM
 cdw
Junior Member

Join Date: May 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
javascript problems in IE 5.1 for mac's

hello I am new here and would like to say hello!

also, as you might expect, I am gonna jump right in and ask if someone can tell me why this script don't work in IE 5.1 on mac (works fine in netscape and explorer on pc and mac's).
it is for a shopping system I am developing.

the code is meant to add together the costs of items depening on quantity of item and where in the world they are to be shipped.

-----------
<SCRIPT language="JavaScript">
<!-- hide from oldie browsers

function defocus(x) {
}

// roundOff
// rounds off value to precision decimal places
function roundOff(value, precision) {
return OKStrOfMN(value,1,precision);
}

// OKStrOfMN
// rounds off X to N decimal places, ensuring there are at least M leading 0's
// URL
function OKStrOfMN(X, M, N) {
var T, S=new String(Math.round(X*Number("1e"+N)))
while (S.length<M+N) S='0'+S
var y = S.substr(0, T=(S.length-N));
if(N>0) {
y += '.' + S.substr(T, N);
}
return y;
}

function CheckNull(value) {
if (value == "") {
value = "0";
}

return value;
}

}

function calculate(x) {
basicprice = calc(x);

if(Number(basicprice) > 0) {

switch (x.carriage_amount.value) {
case "uk" :
x.postage_and_packaging.value = 0.50;
break
case "europe" :
x.postage_and_packaging.value = 1.00;
break
default :
x.postage_and_packaging.value = 1.50;
break;
}

x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);

// Code to generate a dynamic description!
} else {
x.amount.value = "0";
}

x.amount.value = roundOff(x.amount.value,2);

}

function calc(x) {
x.amount.value = 0;
var y = x.price.length;
var z = x.qty.length;
var a = Number(x.amount.value);
var b,c,d;
d = true;
while(y > 0) {
b = Number(CheckNull(x.price[y-1].value));
c = Number(CheckNull(x.qty[y-1].value));
if(c < 0) {
d = false;
c = 0;
x.qty[y-1].value = c;
}
a += (b * c);
// alert("x.price["+eval(y-1)+"].value = "+x.price[y-1].value+"\nx.qty["+eval(y-1)+"].value = "+x.qty[y-1].value+"\na = "+a);
y--;
}
if(d == false) {
alert("Negative quantities not permitted; these have been set to zero.");
}
a += c * 0.50;
return a;
}

var y = x.price.length;
var z = x.code.length;
var d = "";
if(y != z) alert("Missing items in form; found "+y+" occurrences of price and "+z+" of code.");
var c = 0;
while (c < y) {
if(Number(CheckNull(x.qty[c].value)) > 0) {

}
c++;
}

return d;
}

var r = "";
if(d != "") {
r += ", ";
}
r += q + " " + c;
if(Number(CheckNull(q)) > 1) {
r += "'s";
}
// alert("q = "+q+"\nc = "+c+"\n r = "+r);
return r;
}

function validate_form(x) {
// here is where you may wish to include more sophisticated checking, particularly of the email address.
var e = "";
var r = true;
var z,n,q,t;

t = true;
q = 0;
n = 0;
z = 0;

// alert("x.qty.length = "+x.qty.length);

while(z < x.qty.length) {

// alert("z = "+z);
if(Number(CheckNull(x.qty[z].value)) < 0) {
n++;
} else {
q += Number(CheckNull(x.qty[z].value));
}
z++;
}

if(n > 0) {
e += "\nYou have entered "+n+" negative quantit";
if(n == 1) {
e += "y";
} else {
e += "ies";
}
r = false;
}

if(q == 0) {
e += "\nYou need to select at least one item";
r = false;
}

if(x.name.value == "") {
e += "\nPlease enter a name";
r = false;
}

if(x.address.value == "") {
r = false;
}
if(x.country.value == "") {
e += "\nPlease select a country";
r = false;
}
if(x.postcode.value == "") {
e += "\nPlease enter a postcode or ZIP code";
r = false;
}
if(x.tel.value == "") {
e += "\nPlease enter a telephone number";
r = false;
}
if(x.fax.value == "") {
e += "\nPlease enter a fax number";
r = false;
}
if(x.email.value == "") {
e += "\nPlease enter an email address";
r = false;
}
if(r == false) {
alert("The following must be completed first:\n"+e);
}
return r;
}

// -->
</SCRIPT>
----------

#2
May 20th, 2003, 09:57 PM
 ErikSean
Perl Ronin

Join Date: Mar 2002
Posts: 152
Time spent in forums: < 1 sec
Reputation Power: 12
Er... what error are you getting? Hard to know without the entire page (not that I"m suggesting you post the entire page, but knowing the error might prove helpful)

#3
May 21st, 2003, 05:14 AM
 cdw
Junior Member

Join Date: May 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
Basically, the script takes values from input fields (quantity of items ordered) and applies functions on this to work out the total cost and shipping etc. I get a N.aN in the total box - in IE 5.1 for mac, but on every other browser I get the correct total...
not sure why this could be.

#4
May 21st, 2003, 07:04 AM
 cdw
Junior Member

Join Date: May 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
-------
function calculate(x) {
basicprice = calc(x);

if(Number(basicprice) > 0) {

switch (x.carriage_amount.value) {
case "uk" :
x.postage_and_packaging.value = 0.50;
break
case "europe" :
x.postage_and_packaging.value = 1.00;
break
default :
x.postage_and_packaging.value = 1.50;
break;
}

x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);

// Code to generate a dynamic description!
} else {
x.amount.value = "0";
}

x.amount.value = roundOff(x.amount.value,2);
}
-----

above is where I think the problem lies - the x.amount.value seems to be not liked in ie 5.0 and 5.1 on macs. any ideas?

 Viewing: Dev Shed Forums > Web Design > JavaScript Development > javascript problems in IE 5.1 for mac's

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |