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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:59:34+00:00 2026-06-13T02:59:34+00:00

iam trying to achieve this exact functionalty: http://jsfiddle.net/exttq/ BUT inside using my PHP, right

  • 0

iam trying to achieve this exact functionalty: http://jsfiddle.net/exttq/ BUT inside using my PHP, right now its displaying 2 checkboxes and 2 forms, BUT what I need is: those 2 forms shouldnt be visible unless I check any box..

so, please check whats wrong in below code…

function eshop_extras_checkout($echo){


    $echo .= '

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 

    <script>

    $(".formGroup").hide();
    $("#chooseForm input:checkbox").on("change", function() {
        if($(this).is(":checked")) {
            $("#" + $(this).val()).show();
        }
        else {
            $("#" + $(this).val()).hide();
        }
    });
    ​
</script>';

    $echo .= '<fieldset class="eshop eshop_extra">' . "\n";


    $echo .= ' <form id="chooseForm">
        <input type="checkbox" name="form1" value="form1"> Form1<br>
        <input type="checkbox" name="form1" value="form2"> Form2<br>
    </form>

    <form id="form1" class="formGroup">
        <h2>FORM 1</h2>
        <label>Name</label><input type="text"> <br>
        <label>Address</label><input type="text">
    </form>

    <form id="form2" class="formGroup">
        <h2>FORM 2</h2>
        <label>Username</label><input type="text"> <br>
    </form>';


    $echo .= '<legend>Articles Order Form</legend>' . "\n";



    return $echo;
}

waiitng for your replies…

  • 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-13T02:59:35+00:00Added an answer on June 13, 2026 at 2:59 am

    The problem is that your script executes before the elements are present in the DOM. See:

    //when this line executes:
    $(".formGroup").hide(); //the .formGroup is not present in the DOM yet
    //in other words, the jQuery object is empty and calling .hide() does nothing
    
    //the same happens to this handler binding:
    $("#chooseForm input:checkbox").on("change", ...
    

    Your fiddle’s JS is set to use the onDomReady wrapper, that’s why it works properly there.

    You can put the script below the form’s HTML, and/or simply wrap the script contents inside a DOM ready handler:

    $(function() {
        $(".formGroup").hide();
        $('#chooseForm input:checkbox').on('change', function() {
            if($(this).is(':checked')) {
                $("#" + $(this).val()).show();
            }
            else {
                $("#" + $(this).val()).hide();
            }   
        });
    });
    

    One of jQuery’s best practices to always wrap your code in a DOM ready handler, that is:

    $(document).ready(function() {
        //code here
    });
    

    or the much shorter shorthand:

    $(function() {
        //code here
    });
    

    Both have the same effect, they prevent the code from executing until the DOM is ready.

    Another JavaScript best practice is to put the JS code in the footer of the page (right before the </body>), this way scripts loading won’t block the page rendering and when the DOM parser reaches the scripts, your DOM will be already ready for them.

    Both best practices above are combinable. Nevertheless, simply using the DOM ready handler will solve the issue, as well as moving the scripts to below the form HTML will also suffice.


    Your framework is already loading another copy of jQuery in noConflict mode, that means you can’t use the $ alias in the global scope. To remedy that, you can use this special DOM ready syntax, which will alias jQuery back to $ inside its scope:

    jQuery(function($) {
        $(".formGroup").hide();
        $("#chooseForm input:checkbox").on("change", function() {
            if($(this).is(":checked")) {
                $("#" + $(this).val()).show();
            }
            else {
                $("#" + $(this).val()).hide();
            }
        });
    });
    

    More info on that from the DOM ready handler docs – Aliasing the jQuery Namespace:

    When using another JavaScript library, we may wish to call
    $.noConflict() to avoid namespace difficulties. When this function is
    called, the $ shortcut is no longer available, forcing us to write
    jQuery each time we would normally write $. However, the handler
    passed to the .ready() method can take an argument, which is passed
    the global jQuery object. This means we can rename the object within
    the context of our .ready() handler without affecting other code.

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

Sidebar

Related Questions

I am trying to achieve this: http://jsfiddle.net/BcFVv/2/ This is my local code, but it's
I am trying to achieve this using Expression Blend 3. I need that every
I have seen a few similar questions but I am trying to achieve this.
I am trying to achieve this but i dont know what i should use.
I am trying to achieve this user interface through the layout. But getting issues
I am trying to achieve this effect where a photo gets a repeating pattern
I am trying to achieve something like this. The Expandable List consists of the
I am trying to achieve exactly something like this - a text view on
I am currently trying to achieve something like this: Based on this class, I
What I am trying to achieve is something like this: class object: def __init__(self):

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.