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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:46:33+00:00 2026-05-28T16:46:33+00:00

I am having some problem with my if else statment for my radiobutton form.

  • 0

I am having some problem with my if else statment for my radiobutton form. You can view it live here: http://jsfiddle.net/UDGGS/20/

Jquery:

$(document).ready(function() {

    $("input").click(function() {
        $check = true;
    });

    $("#next1").click(function() {
        if ($check) {
            $("boks1").hide();
            $("boks2").show();
        } else {
            alert('Pick one');
        }
    });

});

HTML:

<div id="boks1">
<h1>What would you like to answer? </h1>
<input type="radio" name="group1" value="0">Answer 1<br>
<input type="radio" name="group1" value="1">Answer 2<br>
<input type="radio" name="group1" value="2">Answer 3<br>
<div id="next1" style="border:1px solid black;">Next question<div>
</div>
<div id="boks2">
<h1>What would you like NOT to answer? </h1>
<input type="radio" name="group2" value="0">Answer 1<br>
<input type="radio" name="group2" value="1">Answer 2<br>
<input type="radio" name="group2" value="2">Answer 3<br>
<div id="next2">Next question 3<div>
</div>

CSS:

#boks2 {display:none;}
#next1 {display:block;}

Why is there not alert raised when I click on next and no radiobuttons have been selected? And why I am not shown the next question when I have selected one and clicked on the next div.

  • 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-28T16:46:34+00:00Added an answer on May 28, 2026 at 4:46 pm

    The problem is simply that you are missing the # from your id selectors:

    $("#boks1").hide();
    $("#boks2").show();
    

    However, you should declare the $check variable in the parent scope of the two functions (so inside the ready event handler):

    $(document).ready(function() {
        var $check = false;
    });
    

    Otherwise, if you click on the “next” button before selecting a radio button, $check will not be defined. And when it does become defined, it’s in the global scope, which is not a good thing.

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

Sidebar

Related Questions

I am working on a windows form project and having some problem with UserControl
Hey, I'm having some difficulty with CSS and IE6 compatibility. URL : http://bit.ly/dlX7cS Problem
I am having some problem here. I am trying to develop a flash database
I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my
I'm having some difficulties with the following problem: I'm making a little game where
I've been having some difficulty in understanding the source of a problem. Below is
I am having some trouble with this code . The problem is when i
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having a problem with some code I've written. I've had to anonymize it,
I'm having a problem with some T-SQL in a SP on SQLServer 2005 comparing

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.