autotom

11-14-2010, 05:55 AM

Hey,

This is my first post!

I'm trying to learn javascript and i have tried to create a simple calculator, I have a calculator that does

x * x = x

but when i try to cut / paste it into another project it just refuses to work!

This is undoubtably VERY BASIC but any help is VERY much appreciated :)

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function fmtPrice(value) {

result="$"+Math.floor(value)+".";

var cents=100*(value-Math.floor(value))+0.5;

result += Math.floor(cents/10);

result += Math.floor(cents%10);

return result;

}

function compute() {

var total_price = (document.forms[0].cost.value)*(document.forms[0].qty.value);

document.forms[0].total_price.value=total_price;

var total_price = fmtPrice(total_price);

document.forms[0].total_price.value=total_price;

}

function resetIt() {

document.forms[0].cost.value="0";

document.forms[0].qty.value="0";

document.forms[0].total_price.value="";

}

// End -->

</SCRIPT>

Here is a link to the page - http://dl.dropbox.com/u/29087/Java%20Laptop%20Calc.html

( so you can view source code, saving me from posting it all here )

what am i doing wrong?!! man java is so much harder than VB!

This is my first post!

I'm trying to learn javascript and i have tried to create a simple calculator, I have a calculator that does

x * x = x

but when i try to cut / paste it into another project it just refuses to work!

This is undoubtably VERY BASIC but any help is VERY much appreciated :)

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function fmtPrice(value) {

result="$"+Math.floor(value)+".";

var cents=100*(value-Math.floor(value))+0.5;

result += Math.floor(cents/10);

result += Math.floor(cents%10);

return result;

}

function compute() {

var total_price = (document.forms[0].cost.value)*(document.forms[0].qty.value);

document.forms[0].total_price.value=total_price;

var total_price = fmtPrice(total_price);

document.forms[0].total_price.value=total_price;

}

function resetIt() {

document.forms[0].cost.value="0";

document.forms[0].qty.value="0";

document.forms[0].total_price.value="";

}

// End -->

</SCRIPT>

Here is a link to the page - http://dl.dropbox.com/u/29087/Java%20Laptop%20Calc.html

( so you can view source code, saving me from posting it all here )

what am i doing wrong?!! man java is so much harder than VB!