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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:08+00:00 2026-05-23T15:32:08+00:00

I am trying to have append and show methods if a check box is

  • 0

I am trying to have append and show methods if a check box is checked, problem is that both the methods do not work at the same time.It shows either the div or append the table.How can i have both the table and div if the check box is checked?

here is the code:

<input type="checkbox"  name="want_nl" id="want_nl" value="newsletters" />age

<div id="div1" class="tb" style="background-color:#0099CC">your img here</div>

<table cellpadding="0" cellspacing="0" border="1" width="100%"  id="newsletters"></table>

$(function(){
$("input[name=want_nl]").click(function(){
        if ($(this).is(":checked"))
        {

            $('#newsletters').append('<table id="newsletter_types"></table>');
            $('#newsletter_types').append('<tr><td colspan="3" ><strong>Optioneel</strong></td></tr>');
            $('#newsletter_types').append('<td valign="top">Zoet-houdertje Chocolade lollys</td>');
            $('#newsletter_types').append('<td valign="top" >15 stuks a &euro; 22,50</td>');
            $('#newsletter_types').append('<td valign="top">uuu</td></tr>');
            $('.tb').show();
        }
        else

            $("#newsletter_types").remove();
            $('.tb').hide();
    });

}); 
  • 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-23T15:32:09+00:00Added an answer on May 23, 2026 at 3:32 pm

    The show/hide problem is a missing pair of curly braces. You have this:

    else
        $("#newsletter_types").remove();
        $('.tb').hide();
    

    … which is the same as this:

    else
    {
        $("#newsletter_types").remove();
    }
    $('.tb').hide();
    

    …where you meant:

    else
    {
        $("#newsletter_types").remove();
        $('.tb').hide();
    }
    

    Separately, there is a problem with your code creating the table on-the-fly (you’re adding cells without rows). Also, $(this).is(':checked') is a very, very convoluted way of finding out if a checkbox element is checked. Just use its checkedproperty directly.

    Here’s a quick edit, changed lines flaged with ** (you may have to scroll right to see them). I just added rows around any cells that didn’t have them; you’ll need to make sure they’re in the right place(s):

    $("input[name=want_nl]").click(function(){
            if (this.checked)                                                          // ** Simplified `checked `check
            {
                // ** below, do just *one* append
                $('#newsletters').append(
                    '<table id="newsletter_types">' +
                    '<tr><td colspan="3"><strong>Optioneel</strong></td></tr>' +
                    '<tr><td valign="top">Zoet-houdertje Chocolade lollys</td></tr>' + // ** Added `tr`
                    '<tr><td valign="top" >15 stuks a &euro; 22,50</td></tr>' +        // ** Added `tr`
                    '<tr><td valign="top">uuu</td></tr>' +
                    '</table>'
                );
                $('.tb').show();
            }
            else
            {                                                                          // ** Added curly braces
                $("#newsletter_types").remove();
                $('.tb').hide();
            }                                                                          // ** Added curly braces
        });
    
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to adapt Andy Langton's show/hide/mini-accordion ( http://andylangton.co.uk/jquery-show-hide ) to work within a
I am trying to learn AJAX for this project at work. I have a
I'm trying to draw a map with pyqt and it does not work. So
I have 2 date pickers that contain check boxes within the button pane. I
I have several functions that I am trying to implement in R(studio). I will
I am trying to create a fieldset that will append a file input field
i have a table that each row have a detail to show. so, when
I am trying to write a jQuery plugin that will have similar functionality to
I am trying to show a graph image which is horizontally long. The problem
Afternoon, I am trying have an HTML file containing a frameset which contains two

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.