Results 1 to 5 of 5
  1. #1
    jdh91 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Getting value from a form

    Hey all, if you all can spare some time, please help me look through my code to see if there's anything wrong with it.

    Java Code:
    HtmlPage page = null;
    HtmlForm getUpdateStatusForm = (HtmlForm) page.getFormByName("postTrustServerUrl");
    
    page = getUpdateStatusForm.getElementById(instance);
    
    try {
              page = getUpdateStatusForm.getInputByValue("Begin").click();
    } catch (IOException ex) {
              Logger.getLogger(postTrustMessage.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    System.out.println(page.asXml());
    I'm using netbeans and HtmlUnit to do some testing. The form postTrustServerUrl has a drop down list and a button called "Begin", and when the user selects a value from the drop down list and clicks the button, the option that the user has selected is supposed to be printed out.

    But somehow Netbeans keeps telling me that my id for getElementById is wrong. Anyone know what's the error?

    Any input is appreciated thanks!

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    what is the variable 'instance'? Where is it initialized?
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    jdh91 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    The variable "instance" is the id of of the drop down list when i open the Url of the postTrustServerUrl in mozilla firefox. I used firebug to inspect the elements.

    Java Code:
    <select id="instance" name="instance">
    <option value="0">All instances</option>
                               .
                               .
                               .
    <option value="23">Instance22</option>
    So supposedly the id for the drop down list is "instance", but even after getting the form, I still can't get the id for the drop down list.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    You've provided a very limited example that demonstrates the problem...I'd suggest posting a more clear example (preferably an SSCCE) that demonstrates the problem
    But somehow Netbeans keeps telling me that my id for getElementById is wrong. Anyone know what's the error?
    What is the exact error? getElementById sounds more like javascript...and java != javascript

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    First off, what framework are you using?
    That is, what is HTMLForm/Page etc from, just to be sure we're all looking at the same thing.

    Next, what is the variable instance set to? You aren't showing us that it is "instance". Debug that to make sure by printing it out just before you use it.

    Finally I'd step through in a debugger and actually look at that form object and see what it thinks it's holding.

Similar Threads

  1. Replies: 1
    Last Post: 05-27-2010, 09:48 PM
  2. Replies: 1
    Last Post: 03-22-2010, 09:03 AM
  3. Replies: 0
    Last Post: 10-31-2009, 09:24 AM
  4. Replies: 10
    Last Post: 08-12-2009, 04:02 PM
  5. Replies: 6
    Last Post: 11-28-2008, 06:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •