Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Using getElementById() to get values from drop down list

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using getElementById() to get values from drop down list

    Hi, I am using Netbeans to write this program. I have this .java page that gets the url of the HtmlPage from the .properties page. And when this page is opened in the browser, there are drop down lists that have values I want to get from the user when he/she has selected, and save it to a database. I'm actually using mozilla firefox to open this page, and using firebug to inspect the drop down list element.

    I know getElementById is a javascript code, however, my friend told me to use it in the .java page. This is how part of my code looks like. What I'm not sure is how to implement getElementById() and where.

    HtmlPage pageMain =EBPage;
    WebRequest postRequestSettings = new WebRequest(
    new URL(getProperties("trustAdmin")), HttpMethod.POST);
    // Set the request parameters
    postRequestSettings.setRequestParameters(new ArrayList());
    postRequestSettings.getRequestParameters().add(new NameValuePair("component", "edit"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("formids", "unixTime,instance,time,description,message"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("page", "Status"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("service", "direct"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("session", "T"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("submitmode", "submit"));
    postRequestSettings.getRequestParameters().add(new NameValuePair("submitname", ""));
     
    // Insert instance of message here
    postRequestSettings.getRequestParameters().add(new NameValuePair("instance", instance));
    // Insert content of message here
    postRequestSettings.getRequestParameters().add(new NameValuePair("message", message));
    // Insert description of message here
    postRequestSettings.getRequestParameters().add(new NameValuePair("description", description));
    // Insert time of message here
    postRequestSettings.getRequestParameters().add(new NameValuePair("time", time));
    // Convert time to unix seconds
    postRequestSettings.getRequestParameters().add(new NameValuePair("unixTime", String.valueOf(System.currentTimeMillis() / 1000)));
    HtmlPage newPage1 = pageMain.getWebClient().getPage(postRequestSettings);
    WebRequest requestSettings = new WebRequest(
    new URL("http://www.google.com"), HttpMethod.GET);
    requestSettings.setRequestParameters(new ArrayList());
    requestSettings.getRequestParameters().add(new NameValuePair("page", "Preview"));
    requestSettings.getRequestParameters().add(new NameValuePair("service", "page"));
    newPage1 = newPage1.getWebClient().getPage(requestSettings);

    And I'm told to insert page.getElementById() in the place shown below:

    HtmlPage page = null;
    page.getElementById() 
    try {
    // Login proxy
    page = (HtmlPage) jsonBrowser.getPage(getProperties("jsonBrowser"));
    String proxyUrl = page.getForms().get(0).getAttribute("action");
    System.out.println("Proxy Url" + proxyUrl);
    WebRequest requestSettings = new WebRequest(
    new URL(proxyUrl), HttpMethod.POST);
    requestSettings.setRequestParameters(new ArrayList());
    requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_PASSWORD", password));
    requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_PRIVATE_CHALLENGE_STATE", ""));
    requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_REQUEST_ID", ""));
    requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_USERNAME", userID));
    // Get the page
    page = page.getWebClient().getPage(requestSettings);
    Logger.getLogger(postTrustMessage.class.getName()).log(Level.INFO, "===================================Login in Trust");
    Logger.getLogger(postTrustMessage.class.getName()).log(Level.INFO, page.getWebResponse().getContentAsString());
    } catch (IOException ex) {
    Logger.getLogger(postTrustMessage.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FailingHttpStatusCodeException ex) {
    Logger.getLogger(postTrustMessage.class.getName()).log(Level.SEVERE, null, ex);
    }
    return page;

    Any help would be greatly appreciated. Thanks.
    Last edited by helloworld922; January 5th, 2011 at 05:00 AM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Using getElementById() to get values from drop down list

    postRequestSettings.setRequestParameters(new ArrayList());

    ArrayList has a generic parameter.

    What about

    postRequestSettings.setRequestParameters(new ArrayList<NameValuePair>());

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using getElementById() to get values from drop down list

    Quote Originally Posted by javapenguin View Post
    postRequestSettings.setRequestParameters(new ArrayList());

    ArrayList has a generic parameter.

    What about

    postRequestSettings.setRequestParameters(new ArrayList<NameValuePair>());
    I'm sorry, but what do you mean by generic parameter? How can getElementById() be used here? Thanks
    Last edited by oric1; January 5th, 2011 at 11:54 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using getElementById() to get values from drop down list

    Quote Originally Posted by oric1 View Post
    I'm sorry, but what do you mean by generic parameter? How can getElementById() be used here? Thanks
    It means to set the array list type using Generics, which has absolutely nothing to do with actually answering your question.

    If I understand your problem completely, what you wish to do is not trivial (dynamically save a user selected value on the fly in a webpage using javascript). I'd recommend the easier route, which is to have the user make all selections in an HTML form, then upon submission of the form go to another page with does all the model/database modification.

Similar Threads

  1. Drag and Drop in JTrees
    By helloworld922 in forum Java Swing Tutorials
    Replies: 4
    Last Post: March 21st, 2014, 11:16 AM
  2. [SOLVED] Drag and drop in MVC
    By Alice in forum Object Oriented Programming
    Replies: 9
    Last Post: December 9th, 2010, 10:16 PM
  3. SpinnerListModel setList(List<?> list)
    By roy epperson in forum Collections and Generics
    Replies: 4
    Last Post: November 29th, 2010, 10:30 AM
  4. Drag and Drop in JTrees
    By helloworld922 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 19th, 2010, 11:51 PM
  5. Struts drop down
    By kalees in forum Web Frameworks
    Replies: 1
    Last Post: January 15th, 2010, 12:56 AM