English 中文(简体)
• 无法在瓦查稿中工作
原标题:Cannot get function for onclick event to work in Javascript

我正试图获得一个<代码>onclick的活动,以便在一些嵌入的 Java字码中开展工作。

我在咨询许多论坛和书本后,尝试了以多种不同方式登记活动手,并修改《守则》以开展工作。

I m sure it s something simple but I m too close to it to see what the problem is! If any could take the time to advise, I would be most appreciative!

此处摘自超文本文件:

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Order Form</title>

<script type = "text/javascript">

function updateTotal() {
    var boltQty = document.getElementbyId("bolt_quantity").value;
    var nutQty = document.getElementbyId("nut_quantity").value;
    var washQty = document.getElementbyId("wash_quantity").value;   
    
    document.getElementById("subtotal").value = 
    totalCost = (2.15 * boltQty) + (0.45 * nutQty) + (0.15 * washQty);
}
</script>
</head>
<body>

<h3>Order Form</h3>

<form id = "orderform" action = "">

<table border = "1" cellpadding = "3">
        <tr>
            <th colspan = "8">Product details</th>
        </tr>
        <tr>
            <th>Item</th>
            <th>Product Code</th>
            <th>Diameter</th>
            <th>Length</th>
            <th>Colour</th>
            <th>Unit Price</th>
            <th>Quantity</th>
            <th>Price</th>

        </tr>
        <tr>
            <td>Bolt</td>
            <td>B113</td>
            <td>9</td>
            <td>50</td>
            <td>Black</td>
            <td>2.15</td>
            <td><input type = "text" id = "bolt_quantity" size = "3" /></td>
            <td><input type = "text" id = "row1" onfocus = "this.blur();" size = "3" /></td>
        </tr>
        <tr>
            <td>Nut</td>
            <td>N234</td>
            <td>5</td>
            <td>n/a</td>
            <td>Silver</td>
            <td>0.45</td>
            <td><input type = "text" id = "nut_quantity" size = "3" /></td>
            <td><input type = "text" id = "row2" onfocus = "this.blur();" size = "3" /></td>
        </tr>
        <tr>
            <td>Washer</td>
            <td>W359</td>
            <td>8</td>
            <td>n/a</td>
            <td>Silver</td>
            <td>0.30</td>
            <td><input type = "text" id = "wash_quantity" size = "3" /></td>
            <td><input type = "text" id = "row3" onfocus = "this.blur();" size = "3" /></td>
        </tr>
    </table>
<p>
<input type = "button" value = "Subtotal" onclick = "updateTotal();" />
<input type = "text" size = "3" id = "subtotal" onfocus = "this.blur();" />
</p>

<p>
<input type = "submit" value = "Submit Order" />
<input type = "reset" value = "Clear Order Form" />
</p>
</form>
</body>
</html>
问题回答
var boltQty = document.getElementbyId("bolt_quantity").value;
var nutQty = document.getElementbyId("nut_quantity").value;
var washQty = document.getElementbyId("wash_quantity").value;  

Wrong function name getElementbyId.
Proper one is getElementById.

职务名称属实。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签