my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Needed a logic? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Needed a logic?" Watch "Needed a logic?" New topic
Author

Needed a logic?

Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
In my JSP page am having two links called "LINK1" and "LINK2".

On click of LINK1 am displaying one DIV1 tag, where as on click of second link am disabling first DIV1 and activating second DIV2. This one am able to achieve by using javascript.


But the problem is on click of second link am calling a javascript where am enabling the DIV2 and also am submitting the page where am interacting with DB and the values should be displayed back to my JSP with enabling the DIV2.

How can I achieve this?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

From Javascript you can submit the form (not sure this is what you looking for) using,

And if you need to enable DIV2 do it in the "onload" of the form by calling a JS function.

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Hi Vijitha,
This is not am asking for, am asking like when am submiting the page am doing some logic where the result of that logic
am transferring to same JSP.
At that time i need DIV2 to be displayed with the results.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

You can set the data as attribute of one of the scopes (request,session etc..) as appropriate and also a flag (which you can use to decide whether to dispaly data or not).
Vaib Gupta
Greenhorn

Joined: May 11, 2009
Posts: 15
May be you will have to include some server side code in this. First time when you load the page neither of your divs are visible. Some flag can be set which is initially false for both the divs. Once you open DIV2 and submit the page pass one request attribute after hitting the DB which jsp can read and display the div.
May be something like:

<div style="display: <%=request.getAttribute('someFlag') %>" >....</div>

I am not sure of the syntax though but something like this might work.
Muthukrishnan Manoharan
Ranch Hand

Joined: Aug 27, 2008
Posts: 91

Or you can use AJAX to send data to the server and interact with db and on return back display the same in the div2 without page refresh..
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Hi Muthukrishnan ,
Thanks for the suggestion, I have already opted for this. But am having a small problem with Ajax like


In my application we are keeping Headers info also in REQUEST, so while fetching back the results am getting my results+Header info, so is there any chance to divide them.
Muthukrishnan Manoharan
Ranch Hand

Joined: Aug 27, 2008
Posts: 91

Why dont you make an XML or JSON object of the response, so that you can make a clear distinction between the header information and your actual response information
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "Needed a logic?" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Kartik Talasu wrote: [/code]In my application we are keeping Headers info also in REQUEST, so while fetching back the results am getting my results+Header info, so is there any chance to divide them.

Why? This seems like a rather odd thing to do.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi kartik, don't go with innerHTML. Why because it works only with IE. When using chrome or firefox or any other browser it wont work.
Peter Jennings
Greenhorn

Joined: Sep 25, 2009
Posts: 9
anusha chaitanya wrote:Hi kartik, don't go with innerHTML. Why because it works only with IE. When using chrome or firefox or any other browser it wont work.


Not quite.

Check W3C DOM Compatibility

innerHTML works on most browsers and it is faster in most cases. IE and Konqueror have issues with tables.

There are debates about whether to use it or not, but not because it is only IE compatible. That was true in 1996, but things have moved on a bit.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi Peter Jennings, I'm sorry, I checked it, it is working in chrome also, I read in a forum that it wont work, but I have tried it, it's working fine on chrome also. Thanks for correcting me.
 
Consider Paul's rocket mass heater.
 
subject: Needed a logic?
 
Similar Threads
Replacing one DIV with another
Http Exception
Struts form bean loading using ajax
link from JQuery is not working
Firebug question