File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Replacing one DIV with another" Watch "Replacing one DIV with another" New topic
Author

Replacing one DIV with another

Divya Chandrasekhar
Greenhorn

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!
Thanks,
Divya


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

Joined: Mar 02, 2005
Posts: 443
    
    1


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

Joined: Jun 04, 2011
Posts: 21

Hi Raj,

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

Thanks,
Divya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61753
    
  67

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 | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacing one DIV with another