Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 check box and radio dial javascript validation
Index -> Web Design
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
johnwboyd




PostPosted: Mon Apr 06, 2009 10:28 am   Post subject: check box and radio dial javascript validation

I'm wondering if you can help me as to how to validate a drop check box and radio dial with this page: http://johnwboyd.net/templates08/car-loan1/2/

and it's js:
http://johnwboyd.net/templates08/car-loan1/2/form.js

How would I validate it in PHP as well?
http://johnwboyd.net/templates08/car-loan1/2/form.php
Also how would I add field validation to that script such as email, address, and so on?



Thanks in advance!
Sponsor
Sponsor
Sponsor
sponsor
jeffgreco13




PostPosted: Mon Apr 06, 2009 9:55 pm   Post subject: Re: check box and radio dial javascript validation

i highly suggest you look into jQuery or Prototype... using one of these frameworks you can cut down the amount of javascript coding.

As you can tell validating radio buttons can be quite obtrusive in javascript:
code:
// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
                 



So i suggest you look into a JS framework.

For speed purposes you're better off validating your required fields using JS. Just to make sure your users enter information. Then usin PHP validate the content. Phone number length, email, etc. etc.

Check out this tutorial for PHP: Sanitize Email
DtY




PostPosted: Tue May 12, 2009 3:09 pm   Post subject: Re: check box and radio dial javascript validation

jeffgreco13 @ Mon Apr 06, 2009 9:55 pm wrote:
For speed purposes you're better off validating your required fields using JS. Just to make sure your users enter information. Then usin PHP validate the content. Phone number length, email, etc. etc.


Validate all information server side. And if you wish to, check client side as well so the user knows right away if they enter something bad. The reason to check everything on the server side is that it can't be stopped, whereas doing it client side, you can shut javascript off, or send a fake http request, and you get bad data in your database.
Display posts from previous:   
   Index -> Web Design
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: