|
Subject:
|
JSP & FRAMES
|
|
Posted By:
|
ibsidd
|
Post Date:
|
1/24/2006 10:45:36 AM
|
I have 2 vertically aligned frames. In my left frame I have a drop down listbox populated w/entries from a resultset of a query to a database. When the user selects an entry(option), the entry (parameter) needs to be passed to the right frame. This is at run time and doesn't use any form or submit button. What is the best way to do this being each frame should have a jsp page.
Any helpful advice? Thanks!
Ibrahim Siddiqui
|
|
Reply By:
|
longjava
|
Reply Date:
|
1/28/2006 5:22:15 AM
|
What you need to do is using javascript from the left frame to notify the right frame each time a user selects a new item from the select object.
Here I wrote a template code of how to notify the right frame from the left frame when there is a rew item is selected. By the way, this code I wrote on-the-fly without testing it so please check the syntax since I might be making mistakes about the syntax.
//File: main.html <html> <head> <script type='text/javascript'> </script> </head> <frameset cols='30%,70%'> <frame src='left.jsp' name='left'> <frame src='right.jsp' name='right'> </framset> <html>
---------------------------------
//File: left.jsp <html> <head> <script type='text/javascript'> function notifyRightFrameWithNewItemSelected( value ) { window.top.frames['right'].updateNewItemSelected( value ); }
function itemSelected() { var oSelect = document.getElementById( 'resultSet' ); if ( oSelect != null ) { var item = oSelect.options[oSelect.selectedIndex].value; notifyRightFrameWithNewItemSelected( item ); } } </script> </head> <body> <%-- Assume your resultset is a List object containing a collection of Strings sending back from the server via request object --%> <% List resultSet = (List) request.getAttribute( "resultSet" ); %> <select name='resultSet' id='resultSet' onselect='itemSelected()'> <% if ( resultSet != null && resultSet.size() > 0 ) { for ( int i = 0; i < resultSet.size(); i++ ) { String item = (String) resultSet.get( i ); %> <option value='<%=item%>'><%=item%></option> <% } } %> </select> </body> </html>
---------------------------------
//File right.jsp <html> <head> <script type='text/javascript'> function updateNewItemSelected( newItem ) { document.myForm.resultSetItem.value = newItem; } </script> </head> <body> <%-- display a selected item from the left frame in the textbox field --%> <form name='myForm' id='myForm'> <input type='text' name='resultSetItem' value=''> </form> </body> </html>
|