By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

Problem with Form?

P: 12
Hi there,

I've really not had much to do with this before, but I've been trying to convert a form for use by a local charity and it appears just not to work:

If anyone could help I would be grateful.

Many thanks,
Mar 16 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
The function you're using is as follows:
Expand|Select|Wrap|Line Numbers
  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. }
and it's called here:
Expand|Select|Wrap|Line Numbers
  1. <FORM NAME="getinput" onSubmit="PostCodeInSwindon(); return false;" enctype="text/plain">
One problem is that it should be:
Expand|Select|Wrap|Line Numbers
  1. onsubmit = "return PostCodeInSwindon();"
Another is that getinput is not global: you need to use document.getinput to refer to the form.

Yet another problem is that you've got 4 characters from the postcode, but you're only checking for 3 (for most of the cases in the switch statement).
Mar 17 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.