Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation help with onclick submit button

    I'm trying to get a submit button to open a thank you page I created (i.e. thankyou.html) only after the user has filled out a series of questions for a form. If they don't fill out the required information, a pop up box informs them to fill out the section (this I have accomplished). I cannot get the submit button to not work if the fields are left un-answered. Can you guys help?

    Thanks for you help.
    --------------------------------------------------------------------------

    This is what I have so far:

    <title>Customer Demographic Data Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" ></meta>
    <style type="text/css">
    body {
    font-family: Times New Roman;
    color: navy;
    background-color: #CCC
    }
    h1, h2, h5 { font-family: Times New Roman; color: black }
    body,td,th {
    color: #000;
    font-family: Times New Roman, Times, serif;
    }
    h1 {
    color: #000;
    }
    h2 {
    color: #000;
    }
    h5 {
    color: #000;
    }
    a {
    font-family: Times New Roman, Times, serif;
    }
    h1,h2,h3,h4,h5,h6 {
    font-family: Times New Roman, Times, serif;
    }
    </style>

    <script type="text/javascript">

    function checkForNumber(fieldValue) {
    var numberCheck = isNaN(fieldValue);
    if (numberCheck == true) {
    window.alert("Please enter a numeric value!");
    return false;
    }
    }

    function confirmSubmit() {
    var email = document.forms[0].email.value;
    if (document.forms[0].fname.value == ""
    || document.forms[0].lname.value == "")
    {
    window.alert("Please enter your first and last name.");
    document.forms[0].lname.focus();
    return false;
    }
    else if (document.forms[0].address1.value == ""
    && document.forms[0].email.value == "")
    {
    window.alert("Please enter your Mailing Address or Email Address!");
    document.forms[0].address1.focus();
    return false;
    }
    else if (email.indexOf("@") == -1
    && document.forms[0].email.value != "")
    {
    window.alert("Please enter a valid e-mail address.");
    document.forms[0].email.focus();
    return false;
    }
    else if (email.indexOf(".") == -1
    && document.forms[0].email.value != "")
    {
    window.alert("Please enter a valid e-mail address.");
    document.forms[0].email.focus();
    return false;
    }

    else if(document.forms[0].city.value == '')
    {
    window.alert("Please enter your City");
    document.forms[0].city.focus();
    return false;
    }
    else if(document.forms[0].state.value == '')
    {
    window.alert("Please enter your State");
    document.forms[0].state.focus();
    return false;
    }
    else if(document.forms[0].zip.value == '')
    {
    window.alert("Please enter your Zip Code");
    document.forms[0].zip.focus();
    return false;
    }

    checkCookie()
    }

    function checkCookie()
    {
    var formInfo = decodeURI(document.cookie);
    var userInfo = formInfo.split("; ");
    var lname = userInfo[0].split("=");
    var fname = userInfo[1].split("=");


    if (lname[1] == document.forms[0].lname.value
    && fname[1] == document.forms[0].fname.value)

    {
    this.close(true);
    window.open("FormDenied.html");
    return false;

    }
    else
    {
    setCookie();
    return true;
    }

    }

    function setCookie()
    {
    var expiresDate = new Date();
    expiresDate.setFullYear(expiresDate.getFullYear() + 1);
    document.cookie = encodeURI("lname=" + document.forms[0].lname.value) + "; expires=" + expiresDate.toUTCString();
    document.cookie = encodeURI("fname=" + document.forms[0].fname.value) + "; expires=" + expiresDate.toUTCString();

    window.alert("Your information has been saved.");
    }

    </script>
    </head>

    <body>
    <p>&nbsp;</p>
    <h1 align="left" style="text-align: left">Kudler Fine Foods contact form</h1>
    <form action="" method="get" enctype="application/x-www-form-urlencoded"
    onsubmit="return confirmSubmit();"
    onreset="return confirmReset();" >
    <blockquote>
    <h2><u>Name</u></h2>
    <p>
    <input type="text" name="fname" id="fname" size="25" />
    <label for="fname"><strong>First Name</strong><br>
    <br>
    </label>
    <input type="text" name="lname" id="lname" size="15" />
    <strong>Last Name</strong></p>
    <h2>---------------------------------------<br>
    <u>Address</u> </h2>
    <p>
    <input type="text" name="address1" id="address1" size="30" />
    <label for="address1"><strong>Address Line 1</strong></label>
    </p>
    <p>
    <input type="text" name="address2" id="address2" size="20" />
    <strong>Address Line 2<br>
    <br>
    </strong>
    <input type="text" name="city" id="city" size="20" />
    <strong>City</strong> </p>
    <p>
    <input type="text" name="state" id="state" size="2" />
    <label for="state2"><strong>State</strong></label>
    </p>
    <p>
    <input type="text" name="zip" id="zip" size="10" maxlength="10" onChange="return checkForNumber(this.value);" />
    <label for="zip2"><strong>Zip Code</strong></label>
    </p>
    <h2>--------------------------------------- </h2>
    <h2> <u>Other Information</u></h2>
    <table>
    <tr>
    <td width=300><strong>Telephone</strong></td>
    <td width=300><p><strong>Email address:</strong></p></td>
    </tr>
    <tr>
    <td>
    <input type="text" name="area" id="area" size="3" maxlength="3" onChange="return checkForNumber(this.value);" />
    <input type="text" name="exchange" id="exchange" size="3" maxlength="3" onChange="return checkForNumber(this.value);" />
    <input type="text" name="phone" id="phone" size="4" maxlength="4" onChange="return checkForNumber(this.value);" /></td>
    <td>
    <input type="text" name="email" id="email" size="30" /></td>
    </tr>
    </table>
    </blockquote>
    <h5>&nbsp;</h5>
    <blockquote><blockquote>
    <h3 align="center">
    <input name="Submit" type="button"

    </h3>
    </blockquote>
    </blockquote>
    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    <input type="button" name="Submit" value = "SUBMIT" onclick = "return confirmSubmit()">

    Your validations of the form
    if (document.forms[0].fname.value == ""
    || document.forms[0].lname.value == "")
    are hardly worthy of the name, as any entry - even a space or a ? - will return false (i.e pass the validation).


    BTW, please follow the posting guidelines and wrap your code in [code] tags. This means use the octothorpe or # button on the toolbar which will insert opening [code] and closing [/codx] - change the X to E - tags . You can edit your previous post.


    “I am so clever that sometimes I don't understand a single word of what I am saying.”
    Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,492 Times in 4,456 Posts
    Change the line
    Code:
    checkCookie()
    to
    Code:
    return checkCookie()
    And next time, *PLEASE* use the [ code ] and [ /code ] tags for code (or use the # button in the tool bar) to keep your code readable.

    Ahhh...also, your submit button is bogus. It's missing the > but in any case it's only a button instead or a submit button.

    Change it to:
    Code:
    <input name="Submit" type="submit">
    There are other problems, but fix those first.

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My apologies for not using the wrap code. I'll do that in the future.

    In the code you posted, how can I get it to open my second page, thankyou.html?

    Thanks

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,492 Times in 4,456 Posts
    Hmmm...Philip is fast. I'm only 50% that way.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,492 Times in 4,456 Posts
    Change the form:
    Code:
    <form action="thankyou.html" method="get" enctype="application/x-www-form-urlencoded"
    onsubmit="return confirmSubmit();"
    onreset="return confirmReset();" >

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great, that did it. Appreciate your help!

  • #8
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Im a newb at this (sorta)

    So im making my friend a web page for his upcoming business, Ive gotten most of the details down, but im having issues with the Submit button as well (I want to be able to click it, get the thankyou.html page to appear and also DL all the info), and I also want to make it to where all the info that is submitted gets downloaded to a MYsql server please help!!

    Heres what I have (forgive me for my Newbness)

    <html>
    <head>
    <title>Hook Up My Dance</title></head><br />
    <br />
    <form action="thankyou.html" method="get" enctype="application/x-www-form-urlencoded"
    onsubmit="return confirmSubmit();" >
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    <meta name="author" content="2011 Vortek Consulting .®" />
    <style type="text/css>[CODE][ICODE]
    Last edited by kyroskata; 08-10-2011 at 09:22 AM.


  •  

    Posting Permissions

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