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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:30:24+00:00 2026-05-25T20:30:24+00:00

In some circumstances I have to detect radio-buttons changes. The problem is the app

  • 0

In some circumstances I have to detect radio-buttons changes. The problem is the app only have the ID of the button it is interested. For example, given that HTML piece:

<label class="required">Type</label><br/>
<span class="vertical">
    <input checked="checked" id="diabetes_type-none" name="diabetes_type" type="radio" value="none" /><label for="diabetes_type-none">No diabetes</label><br />
    <input id="diabetes_type-dm1" name="diabetes_type" type="radio" value="dm1" /><label for="diabetes_type-dm1">DM1</label><br />
    <input id="diabetes_type-dm2" name="diabetes_type" type="radio" value="dm2" /><label for="diabetes_type-dm2">DM2</label><br />
    <input id="diabetes_type-other" name="diabetes_type" type="radio" value="other" /><label for="diabetes_type-other">Other type</label>
    <input class="small free" id="diabetes_type-other_more" name="diabetes_type-other_more" type="text" />
</span>

and given the ID “diabetes_type-other” the app must execute some code each time user checks or unchecks the “Other type” button. The code only must be executed when the user clicks on this radio button or when the user clicks on any other button unchecking a previous “Other type” checked button. If user clicks on DM1 and then clicks on DM2 the function shouldn’t be executed. This is my approach:

$("#" + _var).change(function() {
    alert('changed');
});

Problem here is the code is the function is triggered when user clicks on “Other type” but not when user unchecks this.

Other approach is to obtain radio name and then do something like this:

_radioName = "diabetes_type";  // Obtain programmatically
$("input[name=" + _radioName + "]").change(function() {
    alert('changed');
});

Now the problem is this function is triggered always, on any button click and I need the function to be triggered only when user checks or unchecks the given radio button. You can play with this jsfiddle.

  • 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-25T20:30:25+00:00Added an answer on May 25, 2026 at 8:30 pm

    Fiddle: http://jsfiddle.net/sn7eU/1/
    Examine this code, it should meet your wishes:

    var _radioName = "diabetes_type";  // Obtain programmatically
    var _var = "diabetes_type-other";
    
    #(document).ready(function(){
        var lastChecked = false;
        $("input[name=" + _radioName + "]").change(function() {
            if(this.id == _var) lastChecked = true;
            else if(lastChecked){
               /*The radio input isn't "other". Check if the last checked element equals
                 "other" (lastChecked == true). If true, set lastChecked to false*/
                lastChecked = false;
            } else return; /*The input isn't "other", and the last checked element isn't 
                             "other". Return now. */
    
            alert('changed');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows service that fails to start under some circumstances. When it
Some APIs only support output to files. e.g. a library that converts a BMP
I have a class derived from CTreeCtrl. In some circumstances the user might be
We would like under some circumstances to block the action of the close button
I scrape some sites that occasionally have UTF-8 characters in the title, but that
I have an app which stores some data in .php files in /library/ directory,
I have a small application that has a message only WTL window which does
I have a custom plugin for 3ds Max that interfaces with some managed code
I have a problem that is surely familiar to many: I'm making a call
I have an App that displays thousands of Pin annotations on a google map

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.