Web Analytics Made Easy -
StatCounter Form Validation without any alerts - CodingForum

Announcement

Collapse
No announcement yet.

Form Validation without any alerts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form Validation without any alerts

    How can i have a word appear next to the field(s) which are not filled in when the submit button is pressed. (A bit like wrong information when you log on to your hotmail account)

    Here is the code which i want it to fit into:

    Code:
    <html>
    
    <head>
    <title>Viscalite - Contact Us</title>
    <body onload="document.agreeform.reset()">
    <script type = "text/JavaScript" src = "validation.js">
    
    //Submit Once form validation and "Accept terms" form submission
    //© Dynamic Drive (www.dynamicdrive.com)
    //For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
    </script>
    
    
    <LINK href="form.css" rel="stylesheet" type="text/css">
    </style>
    </head>
    
    <body>
    <form name="agreeform" onSubmit="return defaultagree(this)" method="post" enctype="text/plain" action='mailto:[email protected]'>
    
    <label for="firstname">First Name</label>
    <input type="text" name="firstname" value="" /><br />
    
    <label for="emailaddress">Email Address:</label>
    <input type="text" name="emailaddress" value=""  onChange="javascript:this.value=this.value.toLowerCase();"/><br />
    
    <label for="message">Message</label>
    <textarea name="message"></textarea><br />
    
    <label for="terms">Agree to Terms?</label>
    <input name="agreecheck" type="checkbox" name="terms" class="boxes" onClick="agreesubmit(this)"&gt; /><br />
    
    <input type="submit" value="Submit!" disabled name="submitbutton" id="submitbutton" onSubmit="submitonce(this)" />
    
    </form>
    
    </body>
    </html>
    Get Mozilla Firefox

  • #2
    Form Validation...

    hi,

    I'm assuming that you are using CDO fo the mail server, so ill do this in client side for a change (and practice ans not wrote a client validation script in ages....!!!!)

    function form_check(mailSend) {

    if (mailSend.form.TextBox1.name == "") {
    alert ("Please do something...")
    Textbox1.focus()
    return false;
    } // repeat for all textboxes or textareas...

    termsOption = -1

    for (i=0;i<mailSend.checkbox1[i].checked) {
    termsOption = i
    }

    if (termsOption == -1) {
    alert ("Please read and accept the terms and conditions.")
    return false
    }

    alert ("form submitted. Thank you")
    return true;
    } // only activates if all your form fields have been filled in correctly.

    Please note that this only checks if there are characters in the required fields, it doesn't check WHAT is in the fields. If you need this. You'll need to write a regular expression.

    Ta for now..

    Kai

    Comment


    • #3
      Doesn't work
      Get Mozilla Firefox

      Comment


      • #4
        Have a look at this: http://codingforum.net/showthread.php?t=64683

        Dumpfi's script is quite good. It inserts an 'E' right next to an invalid input, then when you rollover it explains the message. No alert()s
        Jalenack.com .:. YWDA Founder .:. Rounded Corners Maker 1.1! .:. My Blog
        The hardest thing about teaching is not knowing the right answers, but knowing the right questions - Elisabeth Klein
        Pretty buttons does not a great website make.

        Comment


        • #5
          Thanks for that!
          Get Mozilla Firefox

          Comment

          Working...
          X