I'm definitely a newcomer to javacsript. I copied some code from another stackoverflow post to multiply the values in two input elements and put the result into a third element.
The html/javascript is:
function Calculate() {
var qty = document.getElementbyId("MemberQty").value;
alert(qty);
if (qty!='') {
var price = document.getElementbyId("MemberPrice").value;
var mcost = parseint(qty) * parseint(price);
document.getElementbyId("MemberCost").value = mcost;
}
else {
document.getElementbyId("MemberCost").value = '';
}
}
<table>
<tr>
<th>Qty</th>
<th align="left">Type</th>
<th>Price</th>
<th>Cost</th>
</tr>
<tr>
<td align="center">
<input type="text" size="3" style="text-align:right;" name="MemberQty" id="MemberQty" autocomplete="off" />
</td>
<td>Member tickets</td>
<td>$
<input type="text" size="5" value="20" name="MemberPrice" id="MemberPrice" readonly disabled style="background-color:#d9dfe5;border-style:none;" />
</td>
<td align="center">$
<input type="text" size="5" name="MemberCost" id="MemberCost" readonly disabled style="background-color:#d9dfe5;border-style:none;" />
</td>
</tr>
<tr>
<td></td>
<td align="right">
<button onClick="Calculate()">Calculate</td>
<td align="right">TOTAL</td>
<td align="center">$
<input type="text" size="5" id="TotalCharge" disabled readonly style="background-color:#d9dfe5;border-style:none;">
</tr>
</table>
When Calculate() is executed, I immediately get an error "Missing required param: number". The alert dialog doesn't show so it must be the first line of the script that causes the problem.
What am I doing wrong?
Thanks, Pete
parseIntnotparseint. Js is case sensitive.<script>tags in the javascript section of the code snippet. Second, you have two spelling errors in your javascript.getElementbyIdshould begetElementByIdandparseintshould beparseInt. Methods in javascript are always camelcased like thatTypeError: document.getElementbyId is not a function(this is because the b in by is lowercase). Could you show us code that actually produces the error you say it does?