Click to See Complete Forum and Search --> : Object doesn't support property or method


yomac
11-13-2003, 06:23 AM
Hi , I am trying to do a simple calculation of two input boxes and output the answer to a third box whilst rounding the numbers to 2 decimal places. Below is my code but I keep getting an error object doesn't support this property or method for line document.stock.getElementById('mus_tot').value = yourTotal;

CODE:
<script type="text/JavaScript">
function round(number,X)
{
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function purchase_mus(day1,day2)
{
var yourTotal = round((parseFloat(day1)+parseFloat(day2)),2);

document.stock.getElementById('mus_tot').value = yourTotal;


}


</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="stock" method="post" action="add_to_stock_take.asp">
<td width="18%" height="30"><input name="mus_mon" ></td>
<td width="18%" height="30"><input name="mus_tue" >
=</td>

<td width="18%" height="30"><input name="mus_tot" ></td>
<input type="button" width="50" height="20" value="Calculate" onClick="purchase_mus(mus_mon.value,mus_tue.value)"; name="button2">
</form>

Charles
11-13-2003, 06:31 AM
1) getElementById() is a method of the document object.

2) X = (!X ? 2 : X); would be better written as X = X ? X : 2

yomac
11-13-2003, 08:25 AM
Why is it causing an error though. I want to make the variable that does the calculation appear a text box in the form. Is there another way of doing this