Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get values from a dropdownlist

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic