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

  • Home
  • SEARCH
  • 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 724137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:11:16+00:00 2026-05-14T06:11:16+00:00

I’m sure I’ve seen examples somewhere before, but I can’t seem to find them.

  • 0

I’m sure I’ve seen examples somewhere before, but I can’t seem to find them. I have a page which has 5 buttons. I’d like each button to load up a different form, without refreshing. I could use UpdatePanels, but it sounds overkill for this (and bandwidth-costly). I’d like to load all the forms in one go, so clicking through the buttons essentially hides/shows the relevant forms. I can’t do this using the html() method (as-is) since the forms can be quite complicated and contain ASP.NET controls which postback to the server. Instead, I’ve put the forms in individual divs.

I tried doing something like this:

                case "button1":

                    $(".current_form").show();
                    $("#divForm1").prependTo($('.current_form'));
                    break;

                case "button2":

                    $(".current_form").show();
                    $("#divForm2").prependTo($('.current_form'));
                    break;

The problem with this is that the old form always remains there, rather than being replaced.
Is it possible to attach a div to a given container in JQuery? Or is there another method which may be better?

Thanks for any help

full code

<script type="text/javascript">
    $(document).ready(function() {

        $("button").button();
        $("button").click(function() {

            switch ($(this).attr("value")) {
                case "button1":

                    $('.current_form').empty().show();
                    $("#divForm1").clone().prependTo($('.current_form'));
                    break;

                case "button2":

                    $('.current_form').empty().show();

                    $("#divForm2").clone().prependTo($('.current_form'));
                    break;




            }
            return false; //prevent postback
        });



    });

</script>

I’m testing with these divs:

<div class="current_form">
<div id="divForm1" >

 This is div 1

</div>
</div>


<div class="current_form">
<div id="divForm2" >

  This is div 2

</div>
</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-14T06:11:17+00:00Added an answer on May 14, 2026 at 6:11 am

    You can call it like this instead:

    $('.current_form').empty().show();
    $("#divForm1").clone().prependTo($('.current_form'));
    

    Your markup would be like this:

    <!-- Possible <form> tag here -->
    <div class="current_form"></div>
    <!-- Possible </form> tag here -->
    <div id="divForm1">
     This is div 1
    </div>
    <div id="divForm2">
      This is div 2
    </div>
    

    This clears out the form before, and it creates a copy of what you want to prepend to put in .current_form, this means the original is still left and your buttons won’t stop working after the first use.

    Be sure to have your <div id="divFormXX"> elements outside the submitted form so the values from the original don’t get submitted to the server as well.


    Update: better option, less markup and less javascript 🙂
    Markup:

    <div id="divForm1" class="form" style="display: block;">
     This is div 1
    </div>
    <div id="divForm2" class="form">
      This is div 2
    </div>
    

    Javascript:

    $(function() {
      $("button").button().click(function() {
        $(".form").hide();
        $("#divForm" + $(this).attr("value").replace('button','')).show();
        return false;
      });
    });
    

    CSS:

    .form { display: none; } //Hide the forms initially
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.