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

The Archive Base Latest Questions

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

Two options click on checkbox 1 then shows and selects 2 click on paragraph

  • 0

Two options
click on checkbox 1 then shows and selects 2
click on paragraph 2 then shows abcde

option 1 works fine

where am i going wrong on option 2

I would like it to select abcd and one of e

This is the jquery

$(document).ready(function() {
    $('.child').hide();
    $(".parent").click(function() {
        $('#form' + $(this).attr('id')).toggle();
        $(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
    });

});

This is the html

    <fieldset>
        <p>
            <label for="5">1</label>
            <input type="checkbox" name="1" id="5" value="360" class="parent" />$360
        </p>
        <p id="form5" class="child">
            <label for="6">2</label>
            <input type="checkbox" name="2" id="6" value="2" />$180
        </p>
    </fieldset>
<fieldset>
<p name="4" id="1st" class="parent">a</p>
<p id="form1st" class="child">
        <label for="7">a</label>
        <input type="checkbox" name="a" id="7" value="25"  />$25
<br />
        <label for="8">b</label>
        <input type="checkbox" name="b" id="8" value="18"  />$18
<br />
        <label for="9">c</label>
        <input type="checkbox" name="c" id="9" value="18"  />$18
<br />
        <label for="10">d</label>
        <input type="checkbox" name="d" id="10" value="18"  />$18
<br />
        <label for="11">e</label>
        <span id="11">
                <input type="checkbox" name="?" value="18"  />e1
                <input type="checkbox" name="?" value="36"  />e2
                <input type="checkbox" name="?" value="54"  />e3
                <input type="checkbox" name="?" value="72"  />e4
                <input type="checkbox" name="?" value="90"  />e5
                <input type="checkbox" name="?" value="100"  />e6
                <input type="checkbox" name="?" value=""  />other
        </span>
    </p>
</fieldset>

And a demo

http://jsfiddle.net/vRXU3/

  • 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-28T15:43:14+00:00Added an answer on May 28, 2026 at 3:43 pm

    Here is your problem.

    this.checked is undefined in ‘option 2’

    .attr('checked', this.checked)
    

    It works when you click on

     <input type="checkbox" name="1" id="5" value="360" class="parent" />
    

    because it is a checkbox and it has cheched attribute. But when you click on

    <p name="4" id="1st" class="parent">a</p>
    

    with ‘this’ you refer the <p> element which has no checked attribute

    – Update

    $(".parent").click(function() {
    
        var $target = $(event.target);
        var valueOfChecked;
        if ($target.is("input:checkbox")) {
            valueOfChecked = $target.attr('checked');
        } else {
            valueOfChecked = 'checked';
        }
        $(this).parents('fieldset:eq(0)').find('p > input:checkbox').attr('checked', valueOfChecked);
        $(this).parents('fieldset:eq(0)').find('p > span input:checkbox').first().attr('checked', valueOfChecked);
    });
    

    jsfiddle updated example

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

Sidebar

Related Questions

i have two Questions. 1) How to open option menu on click of checkbox
If you go to wordpress admin and then settings->privacy , there are two options
The Code has two options. Option one starts with 1 dollar and doubles everyday
Of these two options: var result = from c in coll where c %
There are two options when setting up your JBPM session. You can put your
Of the following two options... Silverlight app talks directly to Azure Tables Silverlight app
Consider and client server scenario and you got two options: You can include Server's
I want to parse a large XML file and I have two options: Perl
Hy, I have two options to choose from: Client side(with FLASH or Javascript): pro:
I am implementing slideshow. I have two options for paging between images: 1) to

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.