6 Replies - 2436 Views - Last Post: 09 January 2011 - 05:16 PM

#1 arch_devil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 11

How to get values from a dropdownlist

Posted 04 January 2011 - 07:17 PM

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 for the drop down list element is this:

<select id="instance2" name="instance2">    
<option value="0">All instances</option>    
<option value="1">Item0</option>    
<option value="2">Item1</option>    
<option value="3">Item2</option>    
                     .    
                     .    
                     .    
<option value="23">Item22</option>


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!

Is This A Good Question/Topic? 0
  • +

Replies To: How to get values from a dropdownlist

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to get values from a dropdownlist

Posted 04 January 2011 - 07:26 PM

Just as a reminder, your are in the Java forum :)
Better to post your question in the appropriate forum
Was This Post Helpful? 0
  • +
  • -

#3 arch_devil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 11

Re: How to get values from a dropdownlist

Posted 04 January 2011 - 07:32 PM

Sorry, my question isn't java related? But I am using java to create this program in Netbeans. If not, which forum should I go to?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to get values from a dropdownlist

Posted 04 January 2011 - 08:02 PM

May be you are using Netbeans as an editor but for sure the code you posted is not Java code

May be Javascript ? I know nothing about it
Was This Post Helpful? 0
  • +
  • -

#5 arch_devil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-January 11

Re: How to get values from a dropdownlist

Posted 04 January 2011 - 08:14 PM

Okay, thanks :)
Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: How to get values from a dropdownlist

Posted 04 January 2011 - 09:23 PM

getElementById() is a Javascript command.
Java != Javascript!

Moving this to Javascript.
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,146
  • Joined: 08-June 10

Re: How to get values from a dropdownlist

Posted 09 January 2011 - 05:16 PM

with document.getElementById() you get a HTMLElement. the easiest way to get the value of a dropdown list is using the .value property of the select element itself.

with your code that would be
document.getElementById("instance2").value

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1