Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-25-2011, 10:13 AM   PM User | #1
m@m
New to the CF scene

 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
m@m is an unknown quantity at this point
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
m@m is offline   Reply With Quote
Old 07-25-2011, 11:01 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 07-25-2011, 11:22 AM   PM User | #3
m@m
New to the CF scene

 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
m@m is an unknown quantity at this point
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> 
m@m is offline   Reply With Quote
Old 07-26-2011, 08:23 AM   PM User | #4
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:57 PM.


Advertisement
Log in to turn off these ads.