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 4 of 4
  1. #1
    m@m
    m@m is offline
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Javascript Validation Problem

    I use this javascript validation in my form..
    http://www.tizag.com/javascriptT/javascriptform.php

    but without validation values go to database.. Can anyone guide me how to solve this?

    First i import javascript file like this..

    <script type="text/javascript" src="validate.js"></script>

    Part of the My code goes like this....

    PHP Code:
     <form action="Process_reg.php" method="post" name="reg" id="reg" onsubmit="return formValidator()">
                                      <
    div id="accordion" style="width:400px; height:500px; font-size:12px;
                                           font-family:Arial, Helvetica, sans-serif"
    >
                                         
                  
                  
                  
                                            <
    h3><a href="#">General Details</a></h3>
                  
                                              <
    div>
                  
                                                  <
    table cellpadding="5px" cellspacing="5px">
                                                      <
    tr>
                                                          <
    td>First name</td>
                                                          <
    td><input type="text"  name="fname" id="fname" size="20px" title="Must be at least 8 characters."  
                                                                   
    /></td>
                                                      </
    tr
    I just only try o validate email field only... email field goes like this
    PHP Code:
     <tr>
                                                          <
    td>Email</td>
                                                          <
    td><input type="text" name="email" id="email" size="20px"  title="Enter Valid Email Address"
                                                                     
    /></td>
                                                      </
    tr

    My whole code attach here...
    Click here to download

    Thanks

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,744
    Thanks
    18
    Thanked 155 Times in 146 Posts
    You are including a lot of javascript files in your PHP file, so there could be a conflict between those files and validate.js.

    What exactly is in validate.js?...Can you paste the code here?

    Also, before we go any further, can you tell me if you are receiving any JS errors in the error console?

    One final thing: Are you supplementing your client side validation with server side validation? I kind of got the impression that you aren't. You'll want to add server side validation as well, because JS validation can be disabled in the browser.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    m@m
    m@m is offline
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not getting any error in the console....

    here goes the .js code.........

    PHP Code:
    <script type='text/javascript'>

    function 
    formValidator(){
        
    // Make quick references to our fields
        
    var firstname document.getElementById('firstname');
        var 
    addr document.getElementById('addr');
        var 
    zip document.getElementById('zip');
        var 
    state document.getElementById('state');
        var 
    username document.getElementById('username');
        var 
    email document.getElementById('email');
        
        
    // Check each input in the order that it appears in the form!
        
    if(isAlphabet(firstname"Please enter only letters for your name")){
            if(
    isAlphanumeric(addr"Numbers and Letters Only for Address")){
                if(
    isNumeric(zip"Please enter a valid zip code")){
                    if(
    madeSelection(state"Please Choose a State")){
                        if(
    lengthRestriction(username68)){
                            if(
    emailValidator(email"Please enter a valid email address")){
                                return 
    true;
                            }
                        }
                    }
                }
            }
        }
        
        
        return 
    false;
        
    }

    function 
    notEmpty(elemhelperMsg){
        if(
    elem.value.length == 0){
            
    alert(helperMsg);
            
    elem.focus(); // set the focus to this input
            
    return false;
        }
        return 
    true;
    }

    function 
    isNumeric(elemhelperMsg){
        var 
    numericExpression = /^[0-9]+$/;
        if(
    elem.value.match(numericExpression)){
            return 
    true;
        }else{
            
    alert(helperMsg);
            
    elem.focus();
            return 
    false;
        }
    }

    function 
    isAlphabet(elemhelperMsg){
        var 
    alphaExp = /^[a-zA-Z]+$/;
        if(
    elem.value.match(alphaExp)){
            return 
    true;
        }else{
            
    alert(helperMsg);
            
    elem.focus();
            return 
    false;
        }
    }

    function 
    isAlphanumeric(elemhelperMsg){
        var 
    alphaExp = /^[0-9a-zA-Z]+$/;
        if(
    elem.value.match(alphaExp)){
            return 
    true;
        }else{
            
    alert(helperMsg);
            
    elem.focus();
            return 
    false;
        }
    }

    function 
    lengthRestriction(elemminmax){
        var 
    uInput elem.value;
        if(
    uInput.length >= min && uInput.length <= max){
            return 
    true;
        }else{
            
    alert("Please enter between " +min" and " +max" characters");
            
    elem.focus();
            return 
    false;
        }
    }

    function 
    madeSelection(elemhelperMsg){
        if(
    elem.value == "Please Choose"){
            
    alert(helperMsg);
            
    elem.focus();
            return 
    false;
        }else{
            return 
    true;
        }
    }

    function 
    emailValidator(elemhelperMsg){
        var 
    emailExp = /^[w-.+]+@[a-zA-Z0-9.-]+.[a-zA-z0-9]{2,4}$/;
        if(
    elem.value.match(emailExp)){
            return 
    true;
        }else{
            
    alert(helperMsg);
            
    elem.focus();
            return 
    false;
        }
    }
    </script> 

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,744
    Thanks
    18
    Thanked 155 Times in 146 Posts
    The first thing I would do is remove the following markup from validate.js:

    Code:
    <script type='text/javascript'>
    ...and...

    Code:
    </script>
    HTML markup cannot "live" inside of a file with a .js extension. So remove the markup and see if that helps...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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