Using javascript inside a Java program
<p>I am trying to invoke a javascript script inside my java program in order to change the selection of a drop down box. I am attempting to pass my html-scrape Document object gotten from jsoup.connect into my script to select a different value. The default option in the drop menu is 1 month (these are timeframes of data to present); I want to change it to 18 months. This is the method I have devised.</p>

<pre><code>public static void dateFix(Document sData){
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine motor = mgr.getEngineByName("JavaScript");
    motor.put("htmlCode", sData);
    try{
    motor.eval("function dateFix(num) {" +
               "var selObj = htmlCode.getElementById(" + "ddlTimeFrame" + ");"+
               "selObj.selectedIndex = num;}");
    }
    catch(ScriptException e){

    }

    Invocable invocableEngine = (Invocable) motor;
    try{
        invocableEngine.invokeFunction("dateFix(6)");
    }catch(ScriptException e){

    }
    catch(NoSuchMethodException e){

    }
    catch(Exception e){

    }

}
</code></pre>

<p>Thanks for your consideration. Cheers.</p>
