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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:17:35+00:00 2026-05-22T12:17:35+00:00

I’m trying to show an alert if a certain radio button in a group

  • 0

I’m trying to show an alert if a certain radio button in a group is checked and then to check the previously checked radio button again.

I was thinking of two solutions:

  1. Adding a disabled attribute, but click events are then not fired so I can’t pop up an alert.

  2. If I don’t add a disabled attribute, then the checked radio button has already changed inside the click event so I can’t obtain the original checked radio button which I’d like to check again.

Basically, what I currently have is this: http://jsfiddle.net/Jygmn/2/

<input name="r" type="radio" id="r1"> r1<br>
<input name="r" type="radio" id="r2"> r2<br>
<input name="r" type="radio" id="r3"> r3<br>
<input name="r" type="radio" id="r4" disabled> r4<br>

JavaScript:

$('#r3, #r4').click(function() {
    window.alert($('input[name=r]:checked').attr('id'));
    // 1) doesn't alert for #r4 because it's disabled.
    // 2) always alerts r3 when #r3 is clicked but I'd like to
    //    obtain the formerly checked radio button id.
});

How can I obtain the formerly checked radio button in the click event of #r3 (or is there something like a beforeclick event)? Or how can I make click events work for disabled radio buttons?

  • 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-22T12:17:36+00:00Added an answer on May 22, 2026 at 12:17 pm

    I would simply add a list with previously pressed radiobuttons. So you when you get to the one to show the alert for you simply show the alert -> pop from the last in the list/variable and simply set that to checked.

    From the top of my head:

    var lastClick;
    $("input[@name='r']".changed(function () {
    
       if("input[@id='r3']][checked=true]"){
            window.alert("r3 was pressed"); 
            $("#r3").checked = false;
            $(lastClick).checked = true;
        }else{
            lastClick ="#" + GetTheOneSelected;
        }                
    });
    

    Dont remember all the syntax but I hope you get the picture.

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

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.