• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a String out of a dropdown menu

 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm having trouble getting a string variable out of a dropdown form that I have on one of my pages.

What I would like is for the page to store a String value locally that is based on which option in the menu is selected when the form is submitted.

ie: hello
goodbye
good morning

submit

If the user clicks submit when "hello" is selected, the page will store "hello" locally in a String value.

I need this String value to be readable in a JSP statement, if that makes sense

ie (<% user.newPage(helloStringVariable);")

If someone could show me how to do this, it'd be greatly appreciated!

Sam
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of the selected dropdown selection will post to wherever you are posting as a name/value pair. Hopefully, you are going to a Servlet and not straight to a JSP.

More info please
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Gardner:
the page to store a String value locally

You'll have to define what you mean by "locally".
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh, well, first to explain my background. I have one year of Java programming experience through college, and I was hired to write a frontend for some data entry that research lab on campus needed to have done using assorted undergrads (ie, needs to be simple and easy to use, and maintainable). I looked around online (I really don't have any web development experience) and stumbled upon the Sun Application Server and JSP, so I've learned enough in the last few weeks to make a web-deployable interface with a MySQL database.

So, I don't claim that anything I'm doing is remotely close to intelligent. Please phrase your suggestions accordingly.

Anyway, currently I have my app set up to go through a password verification server and then get to the actual data entry page.

At one point, I want the user to have a drop-down list of surveys that they can enter data in. I need the actual text from this list (ie survey1) to be stored on the JSP page that the user is currently on, so the JSP can call a method in a class that I have written that will output the survey's prototype (ie q1 = true or false, q2 has choices a, b, c, etc) as an HTML table.

So, they choose survey1, click submit
and a method is called like createTable(survey1) that'll output the SQL survey prototype as an HTML table.

Let me know if that makes sense, I can't imagine this should be too much trouble but I'm just having issues conceptualizing the whole concept of beans.

Sam
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Gardner:
I need the actual text from this list (ie survey1) to be stored on the JSP page that the user is currently on, so the JSP can call a method in a class that I have written that will output the survey's prototype (ie q1 = true or false, q2 has choices a, b, c, etc) as an HTML table.


JSPs (and HTTP) doesn't work that way. The JSP executes on the server and sends an HTML page to the client. Any user interaction with the page at that point can have no effect on code in the JSP which executed long ago and back on the server.

Perhaps this article can give you a better handle on the JSP life-cycle and how they operate.
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

Or, I should say, is there a way I might be able to do this without creating a separate frame for every survey.

eg: have a frame "survey prototype" that would just call my bean method and create a table based on which survey was chosen.

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a number of ways to proceed.

You could have the dropdown selection trigger a full-page submit and you could render whatever you wanted on the JSP the next time around.

Or, you could submit to an iframe that can hold the results.

Or, if you want to dynamically add the results to the current page, you could start digging into Ajax.
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The iFrame idea sounds just like what I need.

Thanks!
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the iframe idea sounds almost perfect, but...

The dynamic iframe that will be refreshed whenever the "submit" button is clicked will refresh differently for different surveys that the user has selected. How do I send the text of what the user selected to the iframe reference JSP so that it will generate the right context?

Sam
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You update the iframe by either setting its src attribute to a URL, or by making it the target of a form submission. In either case, the seelction can be sent to the server-side resource as a request parameter.
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do I set the FORM ACTION =
value to if I want to just refresh my IFRAME?

I have it sending a request alright, but I can only get my form submit button to open the src of the IFRAME rather than just refresh the IFRAME.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The action is independent of which window the request will be submitted to -- it will be the same no mattrer what. It's the target attribute you want to set to the name of the iframe.
 
Sam Gardner
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, that did it.

Thanks for all the help Bear.

Someone can close this topic now if they want.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic