Problem with Form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • updw123
    New Member
    • Oct 2008
    • 12

    Problem with Form?

    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,
    D
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The function you're using is as follows:
    Code:
    function PostCodeInSwindon() {
    // code here something to extract the first (non-blank) four characters of the postcode
    postcode=document.getinput.postcode.value;
    postcode=postcode.toUpperCase()+'      ';
    postcode=postcode.substring(0,4);
    InSwindon=false;
    // check for those postcodes in Swindon
    switch(postcode) {
    	case "SN1":
    		InSwindon=true;
    		break;
    	case "SN2":
    		InSwindon=true;
    		break;
    	case "SN3":
    		InSwindon=true;
    		break;
    	case "SN4":
    		InSwindon=true;
    		break;
    	case "SN5":
    		InSwindon=true;
    		break;
    	case "SN25":
    		InSwindon=true;
    		break;
    	case "SN26":
    		InSwindon=true;
    		break;
    }
    // display the processed postcode
    getinput.processed.value=postcode;
    // display a different result in an input box depending on whether the postcode is in Swindon or not
    if (InSwindon) {getinput.result.value="Swindon"}
    else {getinput.result.value="Not Swindon"}
    // call a different file depending on whether the postcode was in Swindon or not
    if (InSwindon) {destinationpage = "swindonemail.html" + "?Swindon"; top.location.href = destinationpage }
    else {top.location = "noemail.htm"}
    return
    }
    and it's called here:
    Code:
    <FORM NAME="getinput" onSubmit="PostCodeInSwindon(); return false;" enctype="text/plain">
    One problem is that it should be:
    Code:
    onsubmit = "return PostCodeInSwindon();"
    Another is that getinput is not global: you need to use document.getinp ut 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).

    Comment

    Working...