aspose file tools*
The moose likes JSP and the fly likes Passing Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing Values" Watch "Passing Values" New topic
Author

Passing Values

Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
The short story is this. I build on the JSP page a drop down menu using a bit of java to make a database call (because it needs to be dynamic).
Now, the user should be able to select from the combo-box a value (no problem) but then I need to use that value to pass it to a piece of java code on the page to make another database call in order to grab some peremeters to build a table later on down the page.
I HAVE NO IDEA HOW TO DO ANYTHING IN HTML/JAVASCRIPT...please help me. I have poored over resource but I am simply lost in how to do this.

Thank you so much to anyone who can give me some solid guidance/examples.
[ April 07, 2005: Message edited by: Bear Bibeault ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
on the select

<select onchange="document.formName.submit()"

it will post back the data to your server so you can do your next step. You most likely will have to reselect the option when your page rebuilds the select element.

Eric
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
OK...so I use <select onchange="document.formName.submit()" but how do I get the value back? I am not following, sorry.
I have something that looks like

except the values are placed in by some java code on the page doing an sql call.
Now when the user selects a value I want to drop that value into another sql call to finish the page...something like

Did that make since or am I just being a HTML moron? I would think this should be simple but...I never put HTML or JAVASCRIPT on my resume but appearently it is part of the job.

Thanks again for any help and thanks Eric, sorry about posting in the wrong place.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Now when the user selects a value I want to drop that value into another sql call to finish the page.


You have a common misconception as to how JSP works. JSP is merely a template engine that allows you to dynamically build an HTML page to send to the browser. Once the page is sent to the browser, there is no way to get any code on the server to execute without submitting another request. You cannot just execute snippets of Java in response to a user's action.

Upon the user's selection, you must submit back to the server and re-render the page to make any changes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
OK...so how would you do it then? I noticed the original author of the code used Iframes to just hold sections of java code to execute and had the Iframes hidden...I don't know if I am coming across...I'm just frustrated because I can not figure out how to make something seamingly as simple as this work. If you could elaborate more or direct me to a good how to do it for dummies web-site I would appreaceate it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

The easiest method is what I previously mentioned: repost back to the server and refresh the entire page with appropriate changes.

The iframe business is a rather advanced technique that I've used in the past. By posting to the hidden iframe, a round-trip to the server can be made without refreshing the parent page. The response to the iframe post would contain Javascript that would be used to affect the parent page with the results of the operation.
[ April 07, 2005: Message edited by: Bear Bibeault ]
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
OK, I am doing an onchange in my combo box and then I will forward to another page (identicle to the original) but how do I pass the selected value to the duplicate page...I mean what is teh call to pass it and then how do I get it back out?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Pat,
I would strongly recommend taking some time away from this project to follow a few JSP/Servlet tutorials. There is a chapter in "Core Servlets And Java Server Pages" devoted to explaining how HTML forms work. Without understanding some of the fundamental concepts of web programming all the explanations you get from people in this forum will only confuse you further.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Values
 
Similar Threads
howto ensure event handler finish task
Auto generate drop down list
accessing database using javascript
HashMap or database call
retrieve data from database