Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get values from a dropdownlist

 
Jane Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm a beginner so there are many things I do not know, please have patience with me. Haha.

I have this web browser which opens up a website(which is actually a .java page that sets and gets a page) that has a drop down list showing values that the user can select. And when I the firebug to inspect the elements in the page, what shows in the inspection window is this:



What I'm supposed to do is to get the values and update them automatically to the database. I'm actually using HtmlUnit to do this project, and I've heard how I can use getElementById() to get the values. But I don't know how to start.

Thanks, help would be greatly appreciated!
 
Jane Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I found this code online,



which is actually meant for javascript: How to Get Selected Item in Dropdown Select List. Is there any way that I can modify it to java code to make it run in Netbeans?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem very confused about what happens on the client versus what happens on the server. Java code runs on the server to generate the page in the first place (assuming you are using servlets and JSP), and when the form is submitted to a servlet. JavaScript runs on the client.

So what it is it you are actually trying to accomplish and when?
 
Jane Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry because I don't really know the relationship between the client and the server. But what I'm trying to do here is to get the selected value from a drop down list and save it to the database that I already have.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HtmlUnit is a framework for testing pages. So you running automated tests?

Sounds like you have no need to use JavaScript.
Sounds like you need a form submission.

Eric
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane Lim wrote:I'm sorry because I don't really know the relationship between the client and the server. But what I'm trying to do here is to get the selected value from a drop down list and save it to the database that I already have.


You may want to read this first: http://download.oracle.com/javaee/5/tutorial/doc/bnadr.html

In the doGet/doPost methods you can access the values from the form values once the form has been submitted through the request object using the getParameter(String elementName) method.
 
Jane Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:HtmlUnit is a framework for testing pages. So you running automated tests?

Sounds like you have no need to use JavaScript.
Sounds like you need a form submission.

Eric


So there is absolutely no need to create a javascript page? And what about getElementById()?
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should you need to use getElementById? What are your requirements?
 
Jane Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Albareto McKenzie wrote:Why should you need to use getElementById? What are your requirements?


Because I'm using HtmlUnit for this project, and I'm told to use getElementById to get the values from the drop down list. I'm sorry but what do you mean by requirements?
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what is HtmlUnit but for the few I have read shouldn't make any difference here, the point here is that you want to update the database with the values, do you already have that code in the Servlet? Are you able to see something in the Server side?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic