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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:28:52+00:00 2026-06-18T04:28:52+00:00

when i submit the form with empty fields i get the success message in

  • 0

when i submit the form with empty fields i get the success message in the dialog box. Instead i want to show error message in the dialog box. Please help me to find the solution.

My html code:

<form id="booking" action="" method="post">
  First Name:<input type="text" id="firstName" name="firstName" maxlength="30" /><br/>
  Last Name:<input type="text" id="lastName" name="lastName" maxlength="30"/><br/>
  Contact:<input type="text" id="contact" name="contact" maxlength="15"/><br/>
  Email: <input type="text" id="email" name="email" maxlength="30"/><br/>
  <input id="save" type="button" value="Save" />
  </form>
  <div id="dialog"></div>

Jquery code:

 $('#save').click(function(){
    if(('#firstName').length==0 && ('#lastName').length==0 && ('#contact').length==0 &&   ('#email').length==0){
     $('#dialog').attr('title','Error').text('All fields are required').dialog();
     }else{
     $('#dialog').attr('title','Success').text('Success').dialog();
     }
    });
  • 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-06-18T04:28:54+00:00Added an answer on June 18, 2026 at 4:28 am

    ('#firstName') -> if you are using jQuery this should be $('#firstName')

    this conditions will always return false :
    ('#firstName').length==0 && ('#lastName').length==0 && ('#contact').length==0 && ('#email').length==0

    to get the value length of a input type text:

    $('#firstName).val().length
    

    update:

    try this:

    $('#save').click(function(){
        if($('#firstName').val().length==0 && $('#lastName').val().length==0 && $('#contact').val().length==0 &&   $('#email').val().length==0){
         $('#dialog').text('All fields are required').dialog({title:'Error'});
        } else{
         $('#dialog').text('Success').dialog({title:'Success'});
        }
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using hook form alter in drupal. If the fields left empty I want
Javascript needed to prevent form submit if any of field is empty. all my
I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
here is my script I am playing with jQuery Ajax form submit, without success.
I have a contact form in my flash file with name/email/message fields which a
it should submit form, :driver => :webkit do visit '/things/new' page.should have_content('Login') fill_in 'user_login',
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
I am working on a CSS/HTML submit form that I am going to make
Is it possible to add the OR operator to php isset submit form code
I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/ It authenticates against

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.