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

  • Home
  • SEARCH
  • 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 8213623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:10:55+00:00 2026-06-07T11:10:55+00:00

The function below works as it should. It’s to validate a form. In short,

  • 0

The function below works as it should. It’s to validate a form. In short, I have a couple input fields. If I hit submit and no text has been entered in either input, the validation errors appear. If I fill in one field, only one of the fields will update. But if I hit “submit” again, even without filling in the second form input, the else{} gets fired, not the if{} that should assure it’s filled out, etc.

Not familiar, but is it a return false; issue?

if ($('input[type="text"]:visible').val().length == 0) {
    $('.submitModal').click(function () {
        $('.modal').modal('show'); 
    });
}
else {
    $('.submitModal').click(function () {
        $('.modal').modal('hide'); 
    });
}

Any idea what Im doing wrong?

  • 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-07T11:10:58+00:00Added an answer on June 7, 2026 at 11:10 am

    This is backwards thinking. Bind the click, period. Not conditionally. On click, decide what you want to happen (even if this just means ignoring the click).

    If you do bind a click, filling out the form differently isn’t going to unbind it. And even though you COULD actually unbind it, there’s no great reason to.

    If .submitModal is actually a submit input element (rather than an anchor or button with that class), instead of binding a click listener, bind a submit listener.

    Based on Mike’s own starting point of code, here’s an example (slightly outside the true context, since I don’t have the modal function available without unecessary effort!)

    $('.submitModal').click(function (e) {
        e.preventDefault();
        $('input[type="text"]:visible').each(function() {
            if ($(this).val().length == 0) {                        
                $('.modal').show();                        
            }
            else {
                $('.modal').hide();
            }
        });
    });​
    

    The first thing that’s different is that I pass the event into the click handler, and then preventDefault on it. That prevents the anchor from causing a page refresh.

    But the only other thing I did is swap out the actual .modal() call for a generic jQuery .show() and .hide() just to proof-of-concept the logic.

    Mike, the sample code you wrote was pretty much bang-on (except the preventDefault assuming you do in fact want to prevent default anchor behaviour). Here’s the proof:

    jsfiddle.net/gnaXn/2

    When all visible text fields are filled in, the “modal” hides. When they’re emptied again, the “modal” reappears.

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

Sidebar

Related Questions

i have this jQuery-AJAX code below and a form: <script type=text/javascript> $(document).ready(function () {
My below function that is copied from another function that works fine. Should get
I have the function below. Everything works fine except for the Push , Pop
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
My function below, will take the values from my custom meta fields (after a
I have written a function below: void trans(double x,double y,double theta,double m,double n) {
I have the following function below: public function setupHead($title){ $displayHead .='<!DOCTYPE html PUBLIC -//W3C//DTD
I have an example function below that reads in a date as a string
I have the below method in a singleton class private function encode($inp) { if
In the function below, the code should take a parameter, 1) display an alert

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.