how to validate form

Discussion in 'JavaScript' started by googlehelper, Feb 14, 2009.

  1. #1
    i know who to validate the form . i am using css for the display that's why <ul><li>.

    the normal way of form.fnam=="" id not throwing any error(i am using alert())

    does use of <ul> <li> has anything to do
     
    googlehelper, Feb 14, 2009 IP
  2. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #2
    What programming language do you want to use? You can do it with Javascript, PHP, etc etc etc... be a little more specific for some examples
     
    Grit., Feb 14, 2009 IP
  3. googlehelper

    googlehelper Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    sorry if i am a bit rude but this is a javascript forum page right. i have sorted out all the php issues but want the user to be warned before he submits
     
    googlehelper, Feb 14, 2009 IP
  4. googlehelper

    googlehelper Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    plz give me the exact code to validate at least one of the field
     
    googlehelper, Feb 14, 2009 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Your onsubmit should look like this:

    onsubmit="return validate(this)">
    HTML:
    The Javascript part:

    <script type="text/javascript">
    function validate() {
    
    var error=''; // an empty error string
      if ( document.getElementById('F1').value == '' ) { // id="F1" is empty
      error = error+"\n- F1 cannot be empty.";
      }
      if ( document.getElementById('F1').value.length > 15 ) { // id="F1" has more than 15 characters
      error = error+"\n- F1 cannot be more than 15 characters.";
      }
    
    // add more validation here
    
    if (error != '') { // error string is not empty
    alert('Please correct the following error to continue:'+error)
    return false;
    } else {
    return true;
    }
    
    }
    </script>
    HTML:
     
    ads2help, Feb 17, 2009 IP
  6. googlehelper

    googlehelper Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    googlehelper, Feb 20, 2009 IP