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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:53:01+00:00 2026-06-01T20:53:01+00:00

I tried to write a jquery form check code, if value is empty /

  • 0

I tried to write a jquery form check code, if value is empty / words lengh less than something, unbind submit click, show error hint in some div. then 5 seconds later, bind the submit click. Code in jsfiddle, but the bind/unbind not work as my wish.

JS:

$('#submit').click(function(){
    if($('#title').val().length<10){
        $('#statue').append('You should type more than 10 words');
        $('#submit').unbind("click");
        setTimeout(function (){
            $("#statue").html("");
            $('#submit').bind("click");
        }, 5000);
    }
    if($('#content').val().length<20){
        $('#statue').append('You should type more than 20 words');
        $('#submit').unbind("click");
        setTimeout(function (){
            $("#statue").html("");
            $('#submit').bind("click");
        }, 5000);
    }
    if(!$('#type').val()){
        $('#statue').append('You should select one type.');
        $('#submit').unbind("click");
        setTimeout(function (){
            $("#statue").html("");
            $('#submit').bind("click");
        }, 5000);
    }
});

​
HTML:

<form method="post" action="porcess.php">
    <input id="title" name="title" type="text" />
    <textarea name="content" id="content" cols="40" rows="2"></textarea>
    <select name="type" id="type" size="5">
        <option value="a">Section A</option>
        <option value="b">Section B</option>
        <option value="c">Section C</option>
        <option value="d">Section D</option>
        <option value="e">Section E</option>
    </select>
    <input type="submit" name="submit" id="submit" value="submit" />
</form>
<div id="statue"></div>​
  • 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-01T20:53:03+00:00Added an answer on June 1, 2026 at 8:53 pm

    I changed your code a bit. I tend to cache my elements instead of instantiating them over and over. I also created a separate function that will disable/enable the submit button instead of unbinding the click event, as I think this is more user-friendly than unbinding the click. Lastly, I added a variable that will return true/false depending on the validation, that way you don’t submit the form until everything is as you want it to be.

    See working jsFiddle demo:

    Cache Elements

    var $submit = $('#submit'),
        $statue = $('#statue'),
        $title = $('#title'),
        $content = $('#content'),
        $type = $('#type');
    

    Submit Click Handler

    $submit.click(function() {
    
        var continueSubmit = true;
    
        if ($title.val().length < 10) {
            $statue.append('<br />Title needs more than 10 letters.');
            disableEnable(true);
            continueSubmit = false;    
        }
    
        if ($content.val().length < 20) {
            $statue.append('<br />Content needs more than 20 letters.');
            disableEnable(true);
            continueSubmit = false;
        }
    
        if (!$type.val()) {
            $statue.append('<br />You must select 1 type.');
            disableEnable(true);
            continueSubmit = false;
        }
    
        return continueSubmit;
    });
    

    Function to Disable/Enable Submit Button

    function disableEnable(isDisabled) {
    
        if (!isDisabled) { $statue.html(''); }
        $submit.prop('disabled', isDisabled);
        setTimeout(function() { disableEnable(false); }, 5000);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to write a function to check key code with JavaScript. It's working
I tried to write some sloppy jQuery code for an inline-confirm dialog. It works
I am trying to write a Less than validator for jQuery. I want to
I've tried to write the smallest chunk of code to narrow down a problem.
So Im trying to use jquery's .post function to submit a form and return
Some background: On a recent project, I tried to write a streamlined jQuery plugin
I'm new to jQuery and i'm trying to write some code to go through
So what I want to do is to submit a form using jQuery's AJAX
I want to use a JQuery check all function in a form like this:
I tried to write a script to list all files in directories and subdirectories

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.