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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:12:13+00:00 2026-05-20T15:12:13+00:00

I have a UI that can either use a checkbox or a pair of

  • 0

I have a UI that can either use a checkbox or a pair of radio buttons with values of 0 and 1 to allow the user to insert a boolean.

I have an event handler being called when the checkbox or either of the radio buttons is clicked on.

If the checkbox is checked, or if the radio button with a value of 1 is selected, I want to do one thing, if the checkbox is not checked, or the radio button with a value of 0 is selected, or if neither radio button is selected, I want to do another.

Here’s the complication – I need to have the same event handler called, regardless of whether it is attached to a check box or a radio button.

So the question is, what is the cleanest way of structuring the code? Element.is(‘checked’) doesn’t work, because it returns true if either radio button is selected. Element.val() doesn’t work, because the checkbox always has constant value.

Ideas?

  • 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-20T15:12:13+00:00Added an answer on May 20, 2026 at 3:12 pm

    use onChange to trigger the event. Then, you can check the TYPE attribute and split the logic there (if checkbox, check if it’s checked, if radio, then check the value):

    $('.myInput').change(function(){
        if($(this).attribute('type')=='radio'){
            ... get the value ...
        } else {
            ... see if it's checked ...
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that can return either a single object or a collection
I have a HQL query that can generate either an IList of results, or
I have a delphi (Win32) web application that can run either as a CGI
I have several aspx pages that can be opened either normally (full screen in
Following on from this question I now have code that can attach to a
I'm doing custom drawing in datagridview cells and I have items that can vertically
I have a program that can have a lot of parameters (we have over
I have a View that can vary significantly, depending on the 'mode' a particular
I have an object that can build itself from an XML string, and write
I have a program that generates text fiels that can be up to 20

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.