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 6594563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:49:40+00:00 2026-05-25T17:49:40+00:00

in an effort to improve my jquery skills i’ve decided to create a form

  • 0

in an effort to improve my jquery skills i’ve decided to create a form and validate it. everything is working fine, but when i submit my form i only get one of the error messages that i’ve created. i should get all the error messages if i try to submit a blank form, why does it stop after it displays the first error message? this is the first question i’ve ever asked on here so please excuse any mangled code that gets posted on this one.

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript" src="js/styles.js"></script>
<title>Form Submit Test</title>
</head>
<body>
<div id="wrapper">
<div class="form_errors">
</div><!--close form_errors-->
<form action="confirmation.html" method="post">
    <table border="0" cellspacing="10" cellpadding="10" align="center" bgcolor="">
        <tbody>
            <tr>
                <td width="100" style="" align="left">
                    User Name
                </td>
                <td width="170" style="" align="left">
                    <input type="text" name="first_name" value="First" id="first_name"/>
                </td>
            </tr>
                <td colspan="1" style="" align="left"></td>
                <td colspan="1" style="" align="left">
                    <input type="text" name="last_name" value="Last" id="last_name"/>
                </td>                   
            </tr>
            <tr>
                <td colspan="1" style="" align="left">
                    Car Make
                </td>
                <td colspan="1" style="" align="left">
                    <select name="car_make" id="car_make">
                        <option>Choose a make</option>
                        <option value="ford">Ford</option>
                        <option value="mercury">Mercury</option>
                        <option value="lincoln">Lincoln</option>
                        <option value="oldsmobile">Oldsmobile</option>
                        <option value="toyota">Toyota</option>
                        <option value="honda">Honda</option>
                        <option value="lexus">Lexus</option>
                    </select>
                </td>
            </tr>                       
            <tr>
                <td colspan="1" style="" align="left">
                    Year
                </td>
                <td colspan="1" style="">
                    <select name="car_year" id="car_year">
                        <option>Choose a year</option>
                        <option value="1990">1990</option>
                        <option value="1991">1991</option>
                        <option value="1992">1992</option>
                        <option value="1993">1993</option>
                        <option value="1994">1994</option>
                        <option value="1995">1995</option>
                        <option value="1996">1996</option>
                        <option value="1997">1997</option>
                        <option value="1998">1998</option>
                        <option value="1999">1999</option>
                        <option value="2000">2000</option>
                        <option value="2001">2001</option>
                        <option value="2002">2002</option>
                        <option value="2003">2003</option>
                        <option value="2004">2004</option>
                        <option value="2005">2005</option>
                        <option value="2006">2006</option>
                        <option value="2007">2007</option>
                        <option value="2008">2008</option>
                        <option value="2009">2009</option>
                        <option value="2010">2010</option>
                        <option value="2011">2011</option>
                    </select>
                </td>
            </tr>       
            <tr>
                <td colspan="1">
                    Select Service
                </td>
                <td colspan="1">
                    <input type="radio" name="service[]" value="quote" class="radio"/> Quote
                </td>
            </tr>   
            <tr>
                <td colspan="1"></td>
                <td colspan="1">
                    <input type="radio" name="service[]" value="pick-up" class="radio"/> Pick Up Car
                </td>
            </tr>
            <tr>
                <td colspan="1"></td>
                <td colspan="1">
                    <input type="radio" name="service[]" value="drop-off" class="radio"/> Drop Off Car
                </td>
            </tr>   
            <tr>
                <td colspan="1"></td>               
                <td colspan="1">
                    <input type="submit" value="Submit" id="submit"/>
                    <input type="reset" value="Reset" id="reset"/>
                </td>
            </tr>
        <!--close tbody-->
        </tbody>
    <!--close table-->
    </table>
</form>
</div>
<!--close wrapper-->
</body>
</html>

jquery:

$(document).ready(function(){
//custom input toggle function
 jQuery.fn.inputtoggle = function(){
  $(this).each(function(index){ 
    var myvalue = $(this).attr("value"); 
    $(this).focusin(function(){
      if($(this).val() == myvalue)
      $(this).val("");
    });  
    $(this).focusout(function(){
      if($(this).val() === "")
      $(this).val(myvalue);
    });
  });    
};
//use custom function on inputs
$("input[type=text]").inputtoggle();      

//style first td in ever tr and add 'td-style' class
$("form table td:first-child").addClass('td-style');    

//hide .form_errors div by default
$(".form_errors").hide();
$("#reset").click(function(){
    $(".form_errors").empty().hide();
});
$("form").submit(function(e){
    /*RADIO BUTTON VALIDATION*/
    //check to see if radio buttons have been checked
    if($("input[type=radio]:checked").val()){
        //if valid, removes content from .form_errors div in case the radio button was previously invalid
        $(".form_errors").empty().hide();
        //prevents div content from flickering and disappearing. 
        //the default action for the input is to submit and post to the next page
        //http://stackoverflow.com/questions/1357118/javascript-event-preventdefault-vs-return-false
    } else{
        $(".form_errors").show().append('<p>Radio button is NOT checked.</p>');
        return false;
    }

    /*FIRST NAME VALIDATION*/

    if($("#first_name").val() == 'First'){
        $(".form_errors").show().append('<p>Please enter your first name.</p>');
        return false;
    }

    var firstName = $("#first_name").val();
    var validName = /[A-Za-z]/;
    if(!validName.test(firstName)){
        $(".form_errors").show().append('<p>You may only enter letters.</p>');
        return false;
    }

    /*FIRST NAME VALIDATION*/

    if($("#last_name").val() == 'Last'){
        $(".form_errors").show().append('<p>Please enter your last name.</p>');
        return false;
    }

    var lastName = $("#last_name").val();
    var validName = /[A-Za-z]/;
    if(!validName.test(lastName)){
        $(".form_errors").show().append('<p>You may only enter letters.</p>');
        return false;
    }
//close form submit
});
//close jquery
});
  • 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-25T17:49:40+00:00Added an answer on May 25, 2026 at 5:49 pm

    In short, if you have a look at your if statements, you are using “return false” after each check. This way the form prevents itself from submitting itself but this also stops the flow of execution and gets out of the whole method straight from the condition-satisfying “if” block. That’s why only the first check, whichever is triggered in the order of how its organized in your code, is executing.

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

Sidebar

Related Questions

I've been making a concerted effort to improve my javascript skills lately by reading
I'm trying to create a method that provides best effort parsing of decimal inputs
In an effort to create a sandbox for CoreGraphics development (which currently consists of
In an effort to brush up on some multithreading/sorting fun, I decided to put
In an effort to improve the image quality I'm getting from a camera I
Made an effort with Elisp, but didn't work - says incorrect number of arguments.
As part of an effort to create a rudimentary revision control system, I would
Effort I've read this question , but I still think there has to be
Yes I know, another HTTP_REFERER effort. I cringe when I see it. But it
How do convert effort estimate say in function points to a specific web framework

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.