表单有问题?

嗨,你好啊,
我以前真的没有做过太多,但我一直试图转换一种表格,供当地慈善机构使用,但似乎不起作用:
Http://www.p-s-i.org.uk/temp/email.html
如果有人能帮忙,我将不胜感激.
多谢,
D

# 回答1


您正在使用的函数如下:

选择 | 换行 | 行号
  1. function PostCodeInSwindon() {
  2. // code here something to extract the first (non-blank) four characters of the postcode
  3. postcode=document.getinput.postcode.value;
  4. postcode=postcode.toUpperCase()+'      ';
  5. postcode=postcode.substring(0,4);
  6. InSwindon=false;
  7. // check for those postcodes in Swindon
  8. switch(postcode) {
  9.     case "SN1":
  10.         InSwindon=true;
  11.         break;
  12.     case "SN2":
  13.         InSwindon=true;
  14.         break;
  15.     case "SN3":
  16.         InSwindon=true;
  17.         break;
  18.     case "SN4":
  19.         InSwindon=true;
  20.         break;
  21.     case "SN5":
  22.         InSwindon=true;
  23.         break;
  24.     case "SN25":
  25.         InSwindon=true;
  26.         break;
  27.     case "SN26":
  28.         InSwindon=true;
  29.         break;
  30. }
  31. // display the processed postcode
  32. getinput.processed.value=postcode;
  33. // display a different result in an input box depending on whether the postcode is in Swindon or not
  34. if (InSwindon) {getinput.result.value="Swindon"}
  35. else {getinput.result.value="Not Swindon"}
  36. // call a different file depending on whether the postcode was in Swindon or not
  37. if (InSwindon) {destinationpage = "swindonemail.html" + "?Swindon"; top.location.href = destinationpage }
  38. else {top.location = "noemail.htm"}
  39. return
  40. }

它在这里被称为:

选择 | 换行 | 行号
  1. <FORM NAME="getinput" onSubmit="PostCodeInSwindon(); return false;" enctype="text/plain">

一个问题是,它应该是:

选择 | 换行 | 行号
  1. onsubmit = "return PostCodeInSwindon();"

另一个原因是,getinput不是全局的:您需要使用Document.getinput来引用表单.
还有一个问题是,您的邮政编码有4个字符,但您只检查了3个字符(对于Switch语句中的大多数情况).

标签: Javascript

添加新评论