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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:55:27+00:00 2026-05-23T14:55:27+00:00

I am trying to use switch() if the check box is checked,but it does

  • 0

I am trying to use switch() if the check box is checked,but it does not work. What is the probem here i could not figure out.
Could you help plz.
here is what i tried

<input type="checkbox" class="che" value="1" />age
<input type="checkbox" class="che" value="2" />sex

$(".che").click(function(){


var chek= $(this).is(":checked") ;
alert(chek);
        switch(chek){
        case 1:
        alert ('ok');
        $('.myTableRow').show();
        break;
        case 2:
        alert('hora');
            $(".myTableRow").hide();
        break;
       }
    });
  • 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-23T14:55:27+00:00Added an answer on May 23, 2026 at 2:55 pm

    chek is a boolean value. It will never be equal to 2 (false is equivalent to 0 and true to 1), so case 2: will never be reached.

    If you want to get the value of the checkbox, you have to call val():

    $(".che").change(function(){
        var chek= $(this).val();
        alert(chek);
        switch(chek){
            case "1":
                alert ('ok');
                $('.myTableRow').show();
            break;
            case "2":
                alert('hora');
                $(".myTableRow").hide();
            break;
        }
    });
    

    But this setup does not seem to be logical. What should happen if both boxes are selected? It will always execute the action of the last selected checkbox.

    Maybe you just want:

    $(".che").change(function(){
        $('.myTableRow').toggle(this.checked); // or !this.checked
    });
    

    Although this is not really better.

    You have to think about how your form should work before you implement any logic.

    Reference: change, toggle

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

Sidebar

Related Questions

I'm trying to use a switch statement to read out what button has been
I'm trying to use a switch statement in Android aplication,where I have to check
I'm trying to use jquery to switch between three images once you click on
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
I'm currently trying to figure out how to perform manual windows authentication in our
I'm trying to use GMFBridge to switch between multiple stream buffer graphs and I
I'm trying to use django-multilingual and setup it properly. But what I found is
I'm trying to use Bing's REST api to geocode. But my 'y' value is
Basically, I am trying to use data from one model to trigger a switch

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.