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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:21:10+00:00 2026-06-02T02:21:10+00:00

Here is my problem, I have a select box where i need to validate

  • 0

Here is my problem,

I have a select box where i need to validate if the val() becomes 0, then append a text insed a span with class error stating that ‘Please select a value’. Else need to remove that div. These happens when i click the submit button. Here is my code,

if ($('.combo option:selected[value==0]')) {
    var error_span = $("div.info-cont ul.map-list li span.right")
        .append("<br>Please select an appropriate value")
        .addClass('error');
} else {

}

Now the problem is, if a value is selected in the selectbox, my appended span should get removed. Any help. Thanks in advance…

  • 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-02T02:21:12+00:00Added an answer on June 2, 2026 at 2:21 am

    I just want to explain this:

    if ($('.combo option:selected[value==0]'))
    

    To check if the selected item from dropdown has value 0, you can use the following:

    if ($('.combo').val() == '0') // simpler and more readable :-)
    

    Then, it will be simpler if you already put the error message somewhere in the document. All you need to do is show/hide it. For example:

    <select id="dropdown-1" class="combo">
      <option value="0">-</option>
      <option value="1">Lorem</option>
      <option value="2">Ipsum</option>
    </select>
    
    <span id="error-dropdown-1" class="error" style="display: none">Please select a value!</span> <!-- hidden by default. can also use CSS instead of style="display: none" -->
    
    <input type="button" id="demo-button" value="Demo" />
    

    And the javascript (+ jquery):

    $('#demo-button').click(function() {
      if ($('.combo').val() == '0') {
        $('#error-dropdown-1').show();
      } else {
        $('#error-dropdown-1').hide();
      }
    });
    

    Here is another example. Useful if you avoid IDs (perhaps you have dynamically generated dorpdowns):

    <script type="text/javascript">
    $(function() {
        $('#demo-button').click(function() {
            $('.combo').each(function() {
                var div = $(this).parents('div').get(0); // get the wrapper
                if ($(this).val() == '0') {
                    $(div).find('.error').show(); // show <span class=".error"> inside the wrapper
                } else {
                    $(div).find('.error').hide(); // hide <span class=".error"> inside the wrapper
                }
            });
        });
    });
    </script>
    
    <div> <!-- wrapper for 1st combo + 1st error message -->
        <select class="combo">
            <option value="0">-</option>
            <option value="1">Lorem</option>
            <option value="2">Ipsum</option>
        </select>
        <span class="error" style="display: none">Please select a value!</span>
    </div>
    
    <div> <!-- wrapper for 2nd combo + 2nd error message -->
        <select class="combo">
            <option value="0">-</option>
            <option value="1">Dolor</option>
            <option value="2">Sit</option>
            <option value="3">Amet</option>
        </select>
        <span class="error" style="display: none">Please select a value!</span>
    </div>
    
    <div> <!-- wrapper for 3rd combo + 3rd error message -->
        <select class="combo">
            <option value="0">-</option>
            <option value="1">Consectetuer</option>
            <option value="2">Adipiscing</option>
            <option value="3">Elit</option>
        </select>
        <span class="error" style="display: none">Please select a value!</span>
    </div>
    
    <input type="button" id="demo-button" value="Demo" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the multi-select box. I tried to select multiple values
I have a javascript function I wrote to append a select box to a
I have problem adding arraylist to list view, will explain about my problem here..
First, sorry for my bad english, I'm French. Here the problem : I have
Here is the problem I have: I have a lot (tens of thousands) of
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Here's my problem: I have a virtual method defined in a .h file that
Here is the problem: we have lots of Javascripts and lots of CSS files,
Here's my problem: I have to call a web service with a secure header
Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing

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.