How to show data from database by onmouseover image
Abhishek Asthana
Ranch Hand
Joined: Sep 08, 2004
Posts: 146
posted
0
Hi. I have got a JSP page, which has a map. On this map there are various cities. I want to display data related to any city, selected by moving cursor over it on the map, picked from database. How do I do this? Please suggest. Thanks, Abhishek
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
This has nothing to do with JSP, but HTML. You need an imagemap that has entries for your points of interest. That imagemap can (on mouseover) trigger any kind of JavaScript action, e.g. changing a div tag that contains the city data, or displaying some kind of tooltip.
Hi Ulf, That I know, that we can trigger any action using onmouseover, but the problem here is that we have to get the data from database, which will be done by JSP scriptlet only. Can I call any JSP scriptlet using onmouseover? Please tell this. Abhishek
No. Once the page has been sent to the browser any opportunity to execute Java code is gone. In order to execute server-side code you must submit back to the server.
Create a table for each possible city with all the information populated in your jsp. Give each table an id="??name of city??" attribute, and a style="visibilty:hidden;display:none". That way each city's information is in the html document when it is sent to the browser, but none of it is visible on the page. Then you can program the mouseover event of javascript to display the information for a specific city by having it find the appropriate table and changing it's style.visibility and style.display attributes.
The above will work well if there are only a few cities to be displayed, but if there are many, you will want to look for a different solution, as the page will be very large and take a long time to load.
The important thing to remember is that JSP tags can only affect information that is put in the html document before it is rendered into html and sent to the browser. Once the html document is rendered and sitting in the browser, all the information you need has to be there, and the only way of manipulating it is through javascript.
You can try Using Ajax. check out this site www.maps.google.com and i think you need something similar. Search for ajax in the html/javascript forum. plenty has been discussed. Although as ulf has suggested you need to use image maps to get the mouseover city name. [ August 05, 2005: Message edited by: Niki Nono ]
Life called,so here I am.<br />Cheers<br />Niki.:-)
Dan Novik
Ranch Hand
Joined: Jan 26, 2005
Posts: 39
posted
0
yes, it is what Ajax is for. You can call server side stuff right from JavaScript
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
With all due respect, this is not a good application for AJAX. Unless we're talking about thousands of cities (or KiloBytes of data per city), it's better to embed the data in the page, either in JavaScript or in invisible elements, much like Merrill suggests. It will be much more responsive that way.