smerny Posted April 9, 2009 Share Posted April 9, 2009 Nothing below the "var result =" line seems to be processed. The "valid" output is just there to troubleshoot, it shows up in my program.... so the error must be somewhere in my "var result="? else { //Calculate var ytotal1 = miles / mpg1 * price; var mtotal1 = ytotal1 / 12; var ytotal2 = miles / mpg2 * price; var mtotal2 = ytotal2 / 12; var ytotal = ytotal1 - ytotal2; var mtotal = ytotal / 12; //Change HTML document.getElementById("output").innerHTML = "valid"; var result = "<br />You are currently spending " + currency(total1) + " a year in gas.<br /><br />Your new vehicle will save you " + currency(ytotal) + " per year.<br /> Your montly savings are " + currency(mtotal) + "."; document.getElementById("output").innerHTML = result; } The currency function is this.... function currency(amount){ if(isNaN(amount)) { amount = 0.00; } var minus = ''; if(amount < 0) { minus = '-'; } amount = Math.abs(amount); amount = parseInt((amount + .005) * 100); amount = amount / 100; s = new String(amount); if(s.indexOf('.') < 0) { s += '.00'; } if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + "$" + s; return s;} Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2009 Share Posted April 9, 2009 It's possible your browser doesn't like the variable assignment to be spread over multiple lines. You could try putting it all on one line.Could be that funky values being passed to currency() are breaking the function. Try alerting total1, ytotal, and mtotal just be be certain what they are.FWIW, I tried all your code in FF3 and got no significant problems, even when I passed null values or divided by zero. A null value did let a "NaN" slip through your filter, but the string still got built.Come to think of it, what IS total1? I don't see it getting assigned. Is that above the snippet? An undefined variable would certainly break this. That should show up in your error console, though, assuming you're using FF. Link to comment Share on other sites More sharing options...
smerny Posted April 9, 2009 Author Share Posted April 9, 2009 yea, it was that i forgot a letter in the variable name.... thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.