wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes How to get values from a dropdownlist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to get values from a dropdownlist" Watch "How to get values from a dropdownlist" New topic
Author

How to get values from a dropdownlist

Jane Lim
Greenhorn

Joined: Jan 03, 2011
Posts: 5
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

Joined: Jan 03, 2011
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jane Lim
Greenhorn

Joined: Jan 03, 2011
Posts: 5
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 08, 2009
Posts: 298
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

Joined: Jan 03, 2011
Posts: 5
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

Joined: Apr 08, 2009
Posts: 298
Why should you need to use getElementById? What are your requirements?
Jane Lim
Greenhorn

Joined: Jan 03, 2011
Posts: 5
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

Joined: Apr 08, 2009
Posts: 298
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get values from a dropdownlist