Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:16:17+00:00 2026-05-29T05:16:17+00:00

I am creating a form validation script and I have check box’s on a

  • 0

I am creating a form validation script and I have check box’s on a couple forms. How can I skip these and only make my form validation check the input fields?

Here is my example.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="Content-Language" CONTENT="en-us">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script>
$(function() {
    var form_default_texts = [];
    form_defaults = function(){
        $("form :input").filter("[type='text']").each(function() {
            if($(this).val()){
                form_default_texts[$(this).name]=$(this).val();
                $(this).blur(function(){
                    if(!$(this).val()){
                        $(this).val(form_default_texts[$(this).name]).css({color:"#EFEFEF"});
                    }
                }).focus(function(){
                    $(this).val('').css({color:'#191919'});
                }).css({color:'#EFEFEF'});
            }
        });
    };
    form_validate = function(form) {    
        var submit = true;
        $(form.elements).filter("[type='text'], [type='password']").each(function() {
            var field = $(this);
            if(form_default_texts[field.name] == field.val()){
                field.focus();
                submit=false;
            }else{
                switch(field.attr('name')){
                case '': case 'submit':
                    //do nothing.
                    break;
                case 'email':
                    form_clear(field);
                    if(valid_email(field.val()) == false){
                        form_error(field);
                        if(submit){field.focus();}
                        submit = false;
                    }
                    break;
                default:
                    form_clear(field);
                    if(field.val() == ''){
                        form_error(field);
                        if(submit){field.focus();}
                        submit = false;
                    }
                };
            }
        });

        return submit;
    };
    valid_email = function(val){
        var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
        if(filter.test(val)){
            return true;
        }else{
            return false;
        }
    };
    form_clear = function(field){
        field.css({background:'#FFFEFB','border-color':'#fafaee'}).next(".error").remove();
    }
    form_error = function(field){
        var form_errors = {fullname:'How do you want to be addressed?',subj:'What is this about?',msg:'What is your message?',email:'Check your email address.',search:'blah blah',q:'testing'};
        var form_error = form_errors[field.attr('name')];
        if(!form_error){form_error='This field is required';}

        field.css({background:'#F8DBDB','border-color':'#E77776'}).after('<span class="error">'+form_error+'</span>');
    }

    window.onload=form_defaults;

});
</script>
</head>
<body>
<div align="center">
<div class="myform" style="padding:25px 0;">
<form action="/contact/" name="contact" onsubmit="return form_validate(this);" method="POST">
<div class="fb"><span class="finfo round">use this form for quick delivery of your message</span></div>
<div class="fb"><div class="lform round">Your Name:</div>
<input type="text" name="fullname" maxlength="100" size="35" class="inputtext" value=""></div>
<div class="fb"><div class="lform round">Contact Email:</div>
<input type="text" id="email" name="email" maxlength="100" size="35" class="inputtext" value=""></div>
<div class="fb"><div class="lform round">Message Subject:</div>
<input type="text" id="subj" name="subj" maxlength="100" size="55" class="inputtext" value=""></div>
<div class="fb"><div class="lform round">Your Message:</div>
<textarea id="msg" name="msg" cols="50" rows="6" class="inputtext"></textarea></div>
<span><input type="submit" name="submit" class="inputbutton mybutton round" value="Send Message" title="Submit Contact Form"></span>
</form>
<form action="/search.php" method="GET" name="search" onSubmit="return form_validate(this);">
    <input type="text" name="q" class="inputtext" value="" style="width:165px;"><input type="submit" class="inputbutton round" value="Search" title="Search">
</form>
<form action="/signup.php" method="GET" name="newsletter" onSubmit="return form_validate(this);">
    <input type="text" name="email" class="inputtext" value="test test asdfsdf" style="width:165px;"><input type="submit" class="inputbutton round" value="Register" title="Register Account">
</form>
<form action="/signup.php" method="GET" name="search2" onSubmit="return form_validate(this);">
    <input type="text" name="email2" class="inputtext" value="test test" style="width:165px;"><input type="submit" class="inputbutton round" value="Register" title="Register Account">
</form>

</div>
</body>

Thanks guys! Updated with working example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:16:18+00:00Added an answer on May 29, 2026 at 5:16 am

    JQuery can select things by attribute e.g.

    $("input[type='text']")
    

    In your case however I think you’d need.

    $(form.elements).filter("[type='text'], :not([type])"); //not([type]) included as browser defaults to text when attribute not present
    

    I recommend having a thorough read through the jQuery docs – very well written, and you’ll find the answers to a lot of jQuery questions there. How to select a particular element is covered by the selector and traversing sections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a browser-based form verification script that checks if the input doesn't have
I'm creating a JSF 2-application and I'm trying to use form validation in the
HiExperts, I am creating a form with a javascript validation function for a radio
I am creating 10 forms dynamically for example form would be like this <form
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
Airports have four-letter ICAO codes. By convention, these are always uppercase. I'm creating a
I have a little checkbox on a signup form im creating which 'must' be
I'm extending the CodeIgniter Form Validation library to check for Alpha Numeric values with
I'm creating small form for iPhone and on that form I do JavaScript validation
I am creating a user form. In this I have textbox and a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.