我试图创建一个 javascript 表单,但我无法让它工作。出现的错误是
- 邮政编码应由字母和数字组成:
- 地址应该是字母数字:
请将每本杂志限制在 500 份或更少
函数 display() { var totprice; var fname、lname、fullname、addr、postocde、电子邮件、电话、lstitem、数量、性别;var prditem1,prditem2,prditem3,2012 年夏季,2012 年秋季,2012 年冬季,totqty;var orddate; fname = document.form1.fname.value; lname = document.form1.lname.value; //全名 = fname + " " + lname; 性别 = document.form1.gender.value; addr = 文档.form1.address.value; 邮政编码 = document.form1.address.value; 电子邮件 = document.form1.email.value; 电话 = document.form1.telephone.value; prditem1 = document.form1.summer.value; prditem2 = document.form1.autumn.value; prditem3 = document.form1.winter.value; summer2012 = parseInt(document.form1.summer2012.value); 秋季 2012 = parseInt(document.form1.autumn2012.value); Winter2012 = parseInt(document.form1.winter2012.value); totqty = 2012 年夏季 + 2012 年秋季 + 2012 年冬季;orddate = 新日期();dispdate = orddate.getMonth() + 1 + "-" + orddate.getDate() + "-" + orddate.getYear(); var alertmsg = ''; var 字母 = /^[a-zàâçéèêêëîïôûùüÿñ-]*$/i var 字母数字 = /^[a-zA-Z0-9/./,/-/\n]+$/; var addrtxt = addr.replace(/(\x0a\x0d|\x0d\x0a)/g, "\n"); var chkpostcode = /^((GIR 0AA)|((([A-PR-UWYZ][A-HK-Y]?[0-9][0-9]?)|(([A-PR-UWYZ] ][0-9] [A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y]))) [0-9][ABD-HJLNP -UW-Z]{2}))$/ var chktelephone = /^0\d{9,10}$/ var chkEmail = /^.+@.+..+$/ var chkquantity = /^([1 -9]?\d|[1-4]\d{2}|500)$/ if (chkEmail.test(email) == false) { alertmsg = alertmsg + " gender1) { alertmsg = alertmsg + "请选择您的性别\n" } if (((document.form1.summer.checked) && (summer2012 <= 0)) || ((document.form1.autumn.checked) && ( fall2012 <= 0)) || ((document.form1.winter.checked) && (winter2012 <= 0))) { alertmsg = alertmsg + "请输入数量" + "\n"; } else if (((!document.form1.summer.checked) && (summer2012 > 0)) || ((!document.form1.autumn.checked) && (autumn2012 > 0)) || ((!document.form1 .winter.checked) && (winter2012 > 0))) { alertmsg = alertmsg + "请选择产品" + "\n"; } var f = document.form1; 如果 (!f.summer.checked && !f.autumn.checked && !f.winter.checked) { alertmsg = alertmsg + " 数量[1] = parseInt(document.form1.autumn2012.value); 数量[2] = parseInt(document.form1.winter2012.value); for (i = 0; i < 3; i++) { totprice = totprice + 数量[i] * price[i]; } 返回(总价);} }
谁能建议我做错了什么?任何帮助将不胜感激。谢谢
这是html -
<form name="form1" method="post">
<fieldset id="fieldset">
<legend id="legend">Order the latest Saraysounds Magazine</legend>
<table width="500" border=0 align="left" cellpadding="4" cellspacing="4">
<tr>
<td colspan="2"><div align="left">First
Name</div></td>
<td colspan="2"><input type="text" name="fname"/>
</td>
</tr>
<tr>
<td colspan="2"><div align="left">Second
Name</div></td>
<td colspan="2">
<input type="text" name="lname"/>
</td>
</tr>
<tr>
<td colspan="2"><div align="left">Gender</div></td>
<td colspan="2">
<input type="radio" name="gender" value="M"/>
Male
<input type="radio" name="gender" value="F"/>
Female </td>
</tr>
<tr>
<td colspan="2"><div align="left">Address</div></td>
<td colspan="2"><textarea name="address" cols="30" rows=5 col=40 wrap=soft> </textarea>
</td>
</tr>
<tr>
<td colspan="2"><div align="left">Postcode</div></td>
<td colspan="2"> <input type="text" name="postcode"/>
</td>
</tr>
<tr>
<td colspan="2"><div align="left">Email</div></td>
<td colspan="2">
<input type="text" name="email"/>
</td>
</tr>
<tr>
<td colspan="2"><div align="left">Telephone</div></td>
<td colspan="2">
<input type="text" name="telephone"/>
</td>
</tr>
<tr>
<td colspan="4"><center>
<strong>Select
Magazine</strong>
</center></td>
</tr>
<tr>
<td width="123"><center>
<strong>Product Name</strong>
</center></td>
<td width="30" ><center>
<strong></strong>
</center></td>
<td ><center>
<strong>Price</strong>
</center></td>
<td>
<strong>Quantity</strong>
</td>
</tr>
<tr>
<td align="right">Summer 2012
</td>
<td>
<input type="checkbox" name="summer" value="Summer 2012"/>
</td>
<td align="center" width="69"><div align="right">20.00 </div></td>
<td width="216"><input name="summer2012" type="text" size="5" value="0"/></td>
</tr>
<tr>
<td align="right">Autumn 2012
</td>
<td>
<input type="checkbox" name="autumn" value="Autumn 2012"/>
</td>
<td align="center" width="69"><div align="right">20.00 </div></td>
<td><input name="autumn2012" type="text" size="5" value="0"/></td>
</tr>
<tr>
<td align="right">Winter 2012
</td>
<td>
<input type="checkbox" name="winter" value="Winter 2012"/>
</td>
<td align="center" width="69"><div align="right">20.00</div></td>
<td><input name="winter2012" type="text" size="5" value="0"/></td>
</tr>
<tr>
<td align="center" colspan="4"><input name="button" type="button" onClick="javascript:display()" value="Submit"/>
<input type="reset" value="Clear Form"/>
</td>
</tr>
</table>
</fieldset>
</form>