/    Sign up×
Community /Pin to ProfileBookmark

Object doesn’t support property or method

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 [B]document.stock.getElementById(‘mus_tot’).value = yourTotal;[/B]

CODE:
[B]<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>[/B]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 13.2003 — [font=georgia]1) getElementById() is a method of the document object.

2) X = (!X ? 2 : X); would be better written as X = X ? X : 2[/font]
Copy linkTweet thisAlerts:
@yomacauthorNov 13.2003 — 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
×

Success!

Help @yomac 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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