不确定我的问题是什么。我正在尝试在“已下订单”字段中显示日期,并将其计入“总计”字段中的总计。沮丧,我可以使用一些帮助。
<html>
<head>
<title>My Order Form</title>
<!-- Modified by: -->
<!-- This web page should display the current date in the txtDate
textbox on the form as well as calculate the order total and display
in the txtTotal textbox on the form. -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<script language="javascript" type="text/javascript">
<!-- hide from old browsers
function enterDate() {
//reads, formats, then displays the current date in the txtDate textbox on the order form
var myDate = new Date();
var myMonthNum = myDate.getMonth();
var myDay = myDate.getDay();
var myYear = myDate.getYear();
var monthNames = new Array()
monthNames[0] = "Jan";
monthNames[1] = "Feb";
monthNames[2] = "Mar";
monthNames[3] = "Apr";
monthNames[4] = "May";
monthNames[5] = "Jun";
monthNames[6] = "Jul";
monthNames[7] = "Aug";
monthNames[8] = "Sep";
monthNames[9] = "Oct";
monthNames[10] = "Nov";
monthNames[11] = "Dec";
var myMonth = monthNames[myMonthNum];
var myNiceDate = myMonth + " " + myDay + ", " + myYear;
document.frmOrder.txtDate.value = myNiceDate;
}
function enterTotal (quantity, price) {
//calculates the price for each item, adds to existing totals, then displays in the txtTotal textbox
var myTotal = parseInt(window.document.frmOrder.txtTotal);
myTotal += (quantity * price);
window.document.frmOrder.txtTotal.value = myTotal;
}
// -->
</script>
</head>
<body onLoad="enterDate(); window.document.frmOrder.txtWidget.focus()">
<h1 align="center">Totally Useless Parts</h1>
<h2 align="center">Order Form</h2>
<hr>
<form action="mailto:email@email.com" method="post"
enctype="text/plain" name="frmOrder" id="frmOrder">
<table width="100%" border="0" cellspacing="0" cellpadding="5"
summary="Contains the form elements for the order form">
<tr valign="top">
<td> </td>
<td> </td>
<td><div align="right"></div></td>
<td><div align="right">Order Placed:
<input name="txtDate" type="text" id="txtDate"/>
</div></td>
</tr>
<tr valign="top">
<td>Item</td>
<td>Quantity</td>
<td> </td>
<td>Mail To: </td>
</tr>
<tr valign="top">
<td>Widgets </td>
<td><input name="txtWidget" type="text" id="txtWidget" size="4"
onChange="enterTotal(document.frmOrder.txtWidget, 4.99)"/>
(@ $4.99 each)</td>
<td> </td>
<td rowspan="5"><textarea name="txaAddress" cols="50" rows="6" id="txaAddress"></textarea></td>
</tr>
<tr valign="top">
<td>Gizmos</td>
<td><input name="txtGizmo" type="text" id="txtGizmo" size="4"
onChange="enterTotal(document.frmOrder.txtGizmo.value, 2.50)"/>
(@ $2.50 each) </td>
<td> </td>
</tr>
<tr valign="top">
<td>Thing-a-ma-jigs</td>
<td><input name="txtThing" type="text" id="txtThing" size="4"
onChange="enterTotal(document.frmOrder.txtThing.value, 0.95)"/>
(@ $0.95 each) </td>
<td> </td>
</tr>
<tr valign="top">
<td colspan="2"><hr></td>
<td> </td>
</tr>
<tr valign="top">
<td align="right">Total:</td>
<td>$
<input name="txtTotal" type="text" id="txtTotal" value="0" onChange="enterTotal()"/>
(US) </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
我看到的一个问题是用于获取myDay的mydate;它应该是myDate(区分大小写)
还有很多其他错误。也许你应该使用DOM来从表单中获取每个更改的所有值,否则应用程序将不健壮。
正如Jayantha所说,使用Firebug,我也建议使用Firefox的错误控制台。它将有助于确定Javascript错误。
答案 1 :(得分:0)
getDay()
返回一个整数,表示从1到6的星期几。
getYear()
返回年份减去1900并且已弃用。请改用getFullYear()
。
所以,你可以做这样的事情
var myDate = new Date(),
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'],
months =["Jan","Feb","Mar","Apr","May", "Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"],
myNiceDate = months[myDate.getMonth()] + " " +
days[myDate.getDay()] + ", " +
myDate.getFullYear();
console.log(myNiceDate);