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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:54:18+00:00 2026-06-01T05:54:18+00:00

I am having an error where my JQuery works initially upon radio click, but

  • 0

I am having an error where my JQuery works initially upon radio click, but after toggling the radio buttons a few times, it breaks.

What is the proper way to update page text in CSS with 2+ radio questions using JQuery? The toggling of the multiple radio buttons (upon user click) should work indefinitely as it’s a simple, basic if condition.

Code:

var q1 = $("input[name=q1]:radio");
var q2 = $("input[name=q2]:radio");
var q3 = $("input[name=q3]:radio");

var a1 = "foo";
var a2 = "bar";
var aa = "bas";

q1.change(function () {
  $("input:checked").each(
    function () {
        if ($(this).val() == "Yes") {
          $("#a1").text(a1);
        } else { 
          $("#a1").text("");
        };
    }
    );
})

q2.change(function () {
  $("input:checked").each(
    function () {
        if ($(this).val() == "Yes") {
          $("#a2").text(a2);
        } else { 
          $("#a2").text("");
        };
    }
    );
})

.change();

HTML

Question 1 Here?<br />
<input type="radio" name="q1" id="q1-y" value="Yes" />Yes
<input type="radio" name="q1" id="q1-n" value="No" />No
<br />
Question 2 Here?<br />
<input type="radio" name="q2" id="q2-y" value="Yes" />Yes 
<input type="radio" name="q2" id="q2-n" value="No" />No 
<br />
Question 3 Here?<br />
<input type="radio" name="q3" id="q3-y" value="Yes" />Yes 
<input type="radio" name="q3" id="q3-n" value="No" />No 


 <div id="a1"></div>
 <div id="a2"></div>
 <div id="a3"></div>
 <div id="aa"></div>

I’d like to insert text into the Divs based on what is checked in the radio buttons. As mentioned above, the JQuery appears to work initially, but after 3+ clicks, the if statements don’t work.

Thanks

  • 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-01T05:54:20+00:00Added an answer on June 1, 2026 at 5:54 am

    The problem lies in these lines:

    $("input:checked").each(
    

    This means the condition of every checked input is being used to determine what should be displayed, when it should only be one set of radio buttons informing the decision. The problem doesn’t appear until multiple radio button sets have been checked. A quick fix is to say:

    q1.change(function () {
        $("input[name=q1]:checked").each(
    

    and similarly for each change handler.

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

Sidebar

Related Questions

I know this has been asked a few times but please bear with me.
Anyone having problems with discus in IE? Works fine in FF but reports problem
I'm having a problem similar to jQuery $.ajax Not Working in IE8 but it
After examining the jQuery source, I see that the problem I am having is
I'm trying to use jQuery-jsonp plugin with jQuery Deferred Objects but I'm having no
I am having problem updating table cell value using jQuery 1.4.2. it all works
The UFrame works in jquery-1.2.3 but not in jquery-1.6.2 you can get the source
I'm having problems with the jQuery stuff for IE8. It works well in Firefox
I'm having a problem with my jQuery code on http://alpha.spherecat1.com/ , but the local
I'm having problems with jQuery after a page gets loaded via an iframe. Here's

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.