SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem adding variables to a function in a form

    Hi, firstly I apologise if the title of this thread isn't quite accurate. I'm sure you've all heard it before but I am a complete newbie to Javascript so again: apologies if this is boring and tiresome to even read, let alone help with!

    I have been asked to make some changes to a form that uses Javascript for the form validation. There is a 'function' that contains the variables of the various form fields and then further code to raise 'alerts' if one of the fields on the form hasn't been filled in. My problem is that for some reason I am unable to add an extra variable to this code after the field of 'County' (this will hopefully make sense when you see the code / link...) and I am stumped as to why. I am able to add variables for all of the other required fields except for 'Postcode' after 'County'. This is the case for both forms. The link is here: http://samdelara.co.uk/previews/banq...ation-form.htm and the code I am trying edit is below. The issues seems to be when I add && isPostcode() to this chunk of code:-

    Code JavaScript:
    function checkAvailibility()
    {
    // re-calculate...
    calculate ();
    if ( isName() && isAddress1() && isTown() && isCounty() && isPostcode() && isTel() && isYourEmail() && isFuncDate() && somethingToQuoteFor() && isYourEmailValid() ) {
      document.ordersummary.emailQuote.value = "No";
      setValue();
     return true;
     }
     else
     {
     return false;
     }
    }

    /************* FULL CODE BELOW ******************/

    Code JavaScript:
    function checkAvailibility()
    {
    // re-calculate...
    calculate ();
    if ( isName() && isAddress1() && isTown() && isCounty() && isPostcode() && isTel() && isYourEmail() && isFuncDate() && somethingToQuoteFor() && isYourEmailValid() ) {
      document.ordersummary.emailQuote.value = "No";
      setValue();
     return true;
     }
     else
     {
     return false;
     }
    }
     
     
    function isName() { if (document.ordersummary.Name.value=="") { alert ("\n Please Enter Your Name")
    document.ordersummary.Name.focus(); return false; } return true; }
    function isAddress1() { if (document.ordersummary.Address1.value=="") { alert ("\n Please Enter Your Address")
    document.ordersummary.Address1.focus(); return false; } return true; }
    function isTown() { if (document.ordersummary.Town.value=="") { alert ("\n Please Enter Your Town")
    document.ordersummary.Town.focus(); return false; } return true; }
    function isCounty() { if (document.ordersummary.County.value=="") { alert ("\n Please Enter Your County")
    document.ordersummary.County.focus(); return false; } return true; }
    function isTel() { if (document.ordersummary.Tel.value=="") { alert ("\n Please Enter Your Telephone Number")
    document.ordersummary.Tel.focus(); return false; } return true; }
    function isPostcode() { if (document.ordersummary.Postcode.value=="") { alert ("\n Please Enter Your Postcode")
    document.ordersummary.Postcode.focus(); return false; } return true; }
    function isYourEmail() { if (document.ordersummary.YourEmail.value=="") { alert ("\n Please Enter Your Email")
    document.ordersummary.YourEmail.focus(); return false; } return true; }
    function isFuncDate() { if (document.ordersummary.FuncDate.value=="") { alert ("\n Please Enter Your Function Date")
    document.ordersummary.FuncDate.focus(); return false; } return true; }
    function isemailonly() { if (document.ordersummary.emailonly.value=="") { alert ("\n Please Enter Your Email Address")
    document.ordersummary.emailonly.focus(); return false; } return true; }

    Any help would be massivley appreciated!!
    Attached Images Attached Images
    Last edited by Mittineague; Jun 17, 2011 at 19:54. Reason: reformatting bbcode tags

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samd102 View Post
    File not found?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange....the forum seems to have not copied my link correctly. I have pasted it again:

    Online Quotation - The Banqueting Hire Service

    Online Quotation - The Banqueting Hire Service

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    How is your code from above being worked in to the already existing checkAvailability function?

    Are you completely replacing that function, or are you trying to get them to co-exist in some manner?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Sorry, the code you saw then was someone elses attempted solution. The original code I was given is below. I'm aware that the code is of poor quality but I've just been asked to do a quick fix and get the 'alerts' working for all of the fields higlighted in pink. The problem seems to arise when I add && isPostcode() to the function checkAvailibility() script....Instead of giving it an alert it just calls the sendquote.php file in a new window....

    Do you have any idea how I can fix this?

    function checkAvailibility()
    {
    // re-calculate...
    calculate ();
    if ( isName() && isAddress1() && isTown() && isCounty() && isPostcode() && isTel() && isYourEmail() && isFuncDate() && somethingToQuoteFor() && isYourEmailValid() ) {
    document.ordersummary.emailQuote.value = "No";
    setValue();
    return true;
    }
    else
    {
    return false;
    }
    }


    function isName() { if (document.ordersummary.Name.value=="") { alert ("\n Please Enter Your Name")
    document.ordersummary.Name.focus(); return false; } return true; }
    function isAddress1() { if (document.ordersummary.Address1.value=="") { alert ("\n Please Enter Your Address")
    document.ordersummary.Address1.focus(); return false; } return true; }
    function isTown() { if (document.ordersummary.Town.value=="") { alert ("\n Please Enter Your Town")
    document.ordersummary.Town.focus(); return false; } return true; }
    function isCounty() { if (document.ordersummary.County.value=="") { alert ("\n Please Enter Your County")
    document.ordersummary.County.focus(); return false; } return true; }
    function isTel() { if (document.ordersummary.Tel.value=="") { alert ("\n Please Enter Your Telephone Number")
    document.ordersummary.Tel.focus(); return false; } return true; }
    function isPostcode() { if (document.ordersummary.Postcode.value=="") { alert ("\n Please Enter Your Postcode")
    document.ordersummary.Postcode.focus(); return false; } return true; }
    function isYourEmail() { if (document.ordersummary.YourEmail.value=="") { alert ("\n Please Enter Your Email")
    document.ordersummary.YourEmail.focus(); return false; } return true; }
    function isFuncDate() { if (document.ordersummary.FuncDate.value=="") { alert ("\n Please Enter Your Function Date")
    document.ordersummary.FuncDate.focus(); return false; } return true; }
    function isemailonly() { if (document.ordersummary.emailonly.value=="") { alert ("\n Please Enter Your Email Address")
    document.ordersummary.emailonly.focus(); return false; } return true; }

    Online Quotation - The Banqueting Hire Service

    Sam


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •