This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Replacing one DIV with another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Replacing one DIV with another" Watch "Replacing one DIV with another" New topic

Replacing one DIV with another

Divya Chandrasekhar

Joined: Jun 04, 2011
Posts: 21

Hi All,
I am fairly new to Java script.
My problem is as follows:
I need to replace one DIV with another.
The first div, "div1", is shown on page entry; "div2" is initially hidden.
"div1" contains a small form. On click of the submit in "div1", the back-end is hit and we fetch some data which then needs to be populated in "div2" when we get redirected back to this page, so I want "div1" to be replaced by "div2".
Any help will be appreciated!

SCJP 6: 96% SCWCD 5: 98%
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443

Have an onload() function which hides/displays the corresponding DIV based on some parameter on the JSP.
Divya Chandrasekhar

Joined: Jun 04, 2011
Posts: 21

Hi Raj,

thanks for your reply. can you please show me an example?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61092

Why are you doing this with JavaScript in the first place? If the decision regarding which section to show is made on the server, simply use a JSP conditional to include the section or not. Including both sections only to completely hide one of them after the page gets to the client makes no sense. Using JavaScript to do this only makes sense if the decision needs to be made on the client rather than the server.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Also, you could use the <logic:present> tag to check whether the data list for section two is null or not. if it is, display section one, else display section two.

Thanks and Regards,
Komal Renu | |
I agree. Here's the link:
subject: Replacing one DIV with another