Access Java Array in Javascript function

Hi, could someone please help me, I have an array that gets populated in java code and I need to see it in a javascript function.
Here's what I have so far:
//In java class for AvgCostChart.jsp
private String[] month;
public String[] getMonth()
{//code to populate
return month;}
Then in my javascript onLoad function I try to access it. I know how to access the values one at a time like this.
var month1='#{AvgCostChart.month[0]}';
But how do I pass this to a function.
I tried assigning to to another array to loop through the values like this:
var myArr = new Array();
myArr'#{AvgCostChart.month}';
alert (myArr[0]);
But that does not work, any one done this before.
I've also tried saving it in the session and then accessing it but can't get that to work either.
Any help will be greatly appreciated.

Hi,
Please go through the following thread:
http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=60147
Hope this helps
Cheers
Girish

Similar Messages

  • Access Java code in Javascript function

    hi all,
    i have a requirement where i need to access a method defined in a plain java class from a javascript function.
    can anyone please let me know, who can i achieve this.
    thanks in advance

    I have a hyperlink in a JSP, onclick of this, i need to perform two tasks:
    (1) the page should be redirected to the same page.
    (2) excute a function which actually defines code to run a perl script.
    so i have wrapped the function in a class and trying to call this function in the javascript function.
    now i am not sure will this work.
    so if there are any other alternatives to achieve this, please share.

  • Accessing java classes from javascript

    Hi,
    I have the following javascript function
    function testjava {   
        var myString = new java.lang.String("Hello world"); // line 1
        alert("len:"+myString.length()); // line 2
    }It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
    Can someone please help..
    Thanks,
    Vijay.

    It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.

  • Can i write java code in JavaScript function

    I want to call JavaBeans within JavaScript function. Can I do it?
    I have a button in JSP . When the button be clicked,the data be inputted will be checked by JavaScript function. If check is ok, then call a Bean's function to write the data to database.
    Please Help!

    well indeed u can write java code in javascript functions. But probably it will not work the way u want it to.
    when u say that u click a button, it means that some client side action is performed. Now if u wud require a java bean to be called then it means that the server needs to be contacted for the same, and if that has to be done, necessarily the form needs to be submitted.
    U can populate values from a java bean and then the same can be made available to a javascript variable / function when the page is loaded rather than, when the button is clicked.
    What u can do is on click of button u can process [display / calulate..etc ] the information which has already been got by the java bean.
    Kris

  • JSP Array to Javascript function :URGENT HELP

    Hi,
    i have problem in sending array from JSP to Javascript function. if you have any answer please let me know asap.
    Thanks in advance.
    -Priya

    Hi Kurt,
    I have written follow. program . but still I'm getting errors.
    I don't know what I'm doing wrong.
    <HTML>
    <HEAD>
    <SCRIPT>
    function showArray()
         var str = new Array (<%for (int j=0; j<jspstr.length; j++);
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));%>);
         alert ("Total elements received: " + str.length);
         for (j in str)
         alert ("element number " + j + " equals " + str[j]);
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM>
    <%String[] jspstr = {"abc", "def", "ghi", "jkl"};%>
    <SCRIPT>
    showArray();
    </SCRIPT>
    </FORM>
    </BODY>
    </HTML>
    com.ibm.servlet.engine.webapp.WebAppErrorReport: C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:135: Undefined variable or class name: jspstr
    for (int j=0; j<jspstr.length; j++);
    ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: jspstr
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: j
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable: j
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\temp\JSP1_0\default_app\_try_xjsp_debug_jspsrc_988535311.java:136: Undefined variable or class name: jspstr
         out.print ("\"" + jspstr[j] + "\"" + (j<(jspstr.length-1)?",":""));
         ^
    5 errors
    Thanks,
    -Priya

  • Passing java parameter to javascript function in oa framework

    hi all,
    can anybody tell how to pass parameter to javascript function from java for example
    OAMessageTextInputBean txtbean = (OAMessageTextInputBean)webBean.findChildRecursive("BuyerPrice");
    String row = "rowid";
    txtbean.setOnKeyUp("javascript:checkNumber("+row+")");
    checknumber is javascript function defined .

    Hi,
    go through http://forum.java.sun.com/thread.jspa?threadID=174157&messageID=539357
    if ur requirement is just to pass a string to a JS function.
    Thanks

  • Setting the value of a java variable in javascript function

    How can i set the value of a java variable in a javascript function?
    <%
    String fName = "";
    %>
    now i want to define a javascript function which can set the value of fName to the value it has been passed.
    <script language="javascript">
    function setJValue(val)
    </script>
    Thanks

    The only way you could simulate this, would be call the same page inside the Javascript function, and send it the parameter that was passed. Then you would have your Java code retrieve this parameter by request.getParameter("value");, and set the variable accordingly.

  • How to pass jsp array to javascript function()

    function delete(var arr[][])
    out.print(arr[1][2]);
    <%String [][] arra=new String[1][2];
    %>
    <select name="" onClick="delete(<%=arra%>)">
    <option>fvfvfdfdfddffdd</option>
    </select>

    Thanks again for constant support .Now , here comes my real problem .
    I'm having a listbox . I need to find out how to get the values selected in a JSP variable .
    Like I'm having names of cities in listbox .When , I click on save button , i need the names of selected cities in JSP variable or an array .
    <html>
    <head>
    <script language="JavaScript">
         function show(acl)
              for(var i=0;i<4;i++)
                   if(acl.aclnames.options.selected)
                        // i don't know what to put here
              alert("in show");
    </script>
    </head>
    <body>
    <form name="acl" method="post">
    <select name="aclnames" multiple="true" size="3">
    <option>Ahmedabad</option>
    <option>Baroda</option>
    <option>Surat</option>
    <option>Rajkot</option>
    </select>
    <input type="button" name="save" value="Save" onClick="show(acl)">
    </form>
    </body>
    </html>

  • Pass a Java Bean into Javascript function.

    Good day. Please help urgent :
    I am trying to pass an instance of MyBean class into a javascript function
    This code is added to the form.
         private String getJavaScriptForLaunchNewComponent()
              StringBuffer sb = new StringBuffer();
              sb.append("<SCRIPT language='JavaScript'>");
              sb.append("    function testFunction(zBean) { ");
              sb.append("popAssetWinSpecs = \"left=250,top=250,width=300,height=300,scrollbars=no,toolbar=no,menubar=no,resizable=no,status=no,titlebar=no,location=no\";");
    sb.append("htmlfile=\"/irj/servlet/prt/portal/prtroot/com.roche.mss.pdf.comp.PDFLauncher?zBean=\"+zBean;");
    sb.append("window.open(htmlfile,\"editWindow\",popAssetWinSpecs);");
    sb.append("return false;");
    sb.append("    }");
    sb.append("</SCRIPT>");
    return sb.toString();
    This code is set in the create component meth
         private Component buildLink(){
              GridLayout grid = new GridLayout(1,1);
              grid.setCellSpacing(5);
              TestBean zBean = new TestBean();
              zBean.setValue("Me Now");
              Link link = new Link("myLink");
              link.addText("Print PDF");
              link.setOnClientClick("testFunction("+zBean +")");
              grid.addComponent(1,1,link);
              return grid;
    Is this possible ????
    Thanks.

    solved it. Thanks

  • Access Java object from Javascript

    Hi
    I'm trying to invoke a Java object from Javascript (scriptengine and all that).
    I want to add scripting features to a GeneXus Java generated app... and I have very basic skills on java too. Sorry for that ;o).
    This is the java code to pass "params" to the scriptengine:
    engine.put("remoteHandle",remoteHandle);
    engine.put("context", context); The remoteHandle (int) and context (com.genexus.ModelContext) pass trough all the gx-java generated programs.
    This javascript works fine:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle).execute( ) ;The remoteHandle conversion is ok (javascript-number to int). The context is optional.
    But if I want to pass context:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle, context).execute( ) ;Fails with this:
    "javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java constructor for 'uftestjs' with arguments 'number,javax.script.SimpleScriptContext' not found."
    Obviously, no conversion is possible with context (javax.script.SimpleScriptContext to com.genexus.ModelContext).
    There is some way to reference de original context, by the object Id??? or something like that???
    Thanks in advance for any replies!!!
    Greetings from Chile. (I hope you can understand my english!)

    Hi
    Well, since this topic is about java programming I think the place is right here.
    (I use some tricks to embed java statements in genexus objects...)
    I will try to get some help at Artech (GX) on how to build something... to get the conversion needed.
    But they are not focussed on support this kind of questions.
    Anyway, I want to know: do I can to reference an object by the objId?
    I want to code something like this:
    com.genexus.ModelContext context =
                     (com.genexus.ModelContex)getTheObjectFromTheJVM(theObjectId);(powered by google translator, ha!)

  • Assign a java array to javascript array

    hi all,
    I am trying to do as below
    <%!
    String messages[]={" is mandatory","Special Characters are not allowed","characters length is more than limit(1000 characters)"};
    %>
    And then
    var errormessages=new Array();
    errormessages=<%=messages%>;
    i am getting some javascript error ....please do help to resolve this.....
    Suggesstions are appreciable
    Thanks
    Raghu

    What version of Java are you using? Have you tried the new Java Plug-In in 6u10? http://jdk6.dev.java.net/6u10ea.html
    The new Java Plug-In should handle this case correctly.

  • Call Java Method From JavaScript Function

    hi everyone
    i need a help in calling Java method from a javaScript method
    ex:
    function confirmAddRecord() {
    cHours =document.getElementById('frmP:ChargeHours').value;
    cSTime =document.getElementById('frmP:ChargeStartTime').value;
    var answer = confirm("Are you sure you want to add Record?")
    if (answer){
    here i want to call the Java Method that is located in session bean that takes the upper params cHours & cSTime
    else{
    return false;
    i know i can do it as an action button but it is required me to be in that way can any one help plz
    Message was edited by:
    casper77

    That depends on the nature of your parameters. I guess you calculate the params on client and then want to submit them. In this case and if you don't want to use Ajax simple add some <input type="hidden"> elements (of course there correspondend components dependent of your framework) and store the params there. If the javascript isn't invoked by a button click, you can use a button nevertheless. Set visible="false" and call
    document.getElementById('client_id_of_my_hidden_button').click();
    (or maybe doClick() dependent on your framework).

  • Cannot read Java array in javascript. Please see my code

    Here is the script
    <webuijsf:script binding="#{temp.script2}" id="script2">
    foo()
    var picture = <%=getApplicationBean1().getPictureDirName()[1].toString()%>;
    </webuijsf:script>
    <webuijsf:body binding="#{temp.body1}" id="body1" onLoad="foo();" style="-rave-layout: grid">
    Error Message
    The content of the form must consist of well-formed character data or markup.
    Can anyone tell me what is the problem
    I would be very greatfull if anyone could help me read a java var or array in a javascript

    http://forum.java.sun.com/thread.jspa?threadID=5143339&messageID=9529903#9529903
    http://forum.java.sun.com/thread.jspa?threadID=5143428&messageID=9530475#9530475
    http://forum.java.sun.com/thread.jspa?threadID=5143443&messageID=9530587#9530587
    http://forum.java.sun.com/thread.jspa?threadID=5143467&messageID=9530764#9530764
    Why are you spamming 4 threads about the same problem? Use one thread and gently use the edit button if you want to add some new information. With 4 separate threads we are missing the overview.

  • Accessing java objects through javascript

    anybody know a how to get an image from java to javascript... example you get an image from a scanner through java... and then want to use it in javascript

    anybody know a how to get an image from java to
    javascript... example you get an image from a scanner
    through java... and then want to use it in javascripthttp://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/java_js.html

  • Access java from javascript in firefox

    Hi,
    I am trying to access java method from javascript.
    It works fine with ie, but firefox somehow brings up the error
    saying the method defined in java is not a function.
    I am calling like.
    document.applets["myapp"].soundAlarm();
    I have put MAYSCRIPT in the applet tag.
    still not works.
    Does anyone have idea ?
    Thanks

    Try with
    document.myapp.soundAlarm();I assume that the name attribute of the APPLET is myapp.
    Note the MAYSCRIPT is useless in your context. MAYSCRIPT is used when from Java you need to access the JSObject.
    See http://www.rgagnon.com/topics/java-js.html for examples.
    Bye.

Maybe you are looking for

  • SUP - Update KB3000850 and other issues

    Hello, I manage a SCCM 2012 R2 Infrastructure. I am trying to add the KB3000850 to my update package and I always get an error message. I tried to resynchronize the SUP and still the same error. Package: Success: The software updates were placed in t

  • Adobe Reader 9 and Wacom Dig Sigs

    Hello all,    First the background:  We have an HP EliteBook 2730p tablet pc with an integrated Wacom Digitizer (pen).  The OS is Windows Vista 32 bit Business edition SP2.  We are using Adobe Reader 9.3.  We have a requirement to digitally sign PDF

  • Suggestions for 4.2.2 desktop

    Is there a "Suggestion" forum or URL to send ideas on how to improve the Palm Desktop software? I have 2: What happened to copy item on the calendar? I would like to copy an appointment or event so I do not have to re-re--retype the same things over

  • Post-Clone script error

    Hello, I am facing post-clone error on 11i O.S aix 5.3 when i run post-clone script on db it got error.share any solution is highly appreciable $ perl adcfgclone.pl dbTier Enter the APPS password [APPS]: First Creating a new context file for the clon

  • Cannot find serial number on box, have tried to see it 3 days now

    I am looking for serial number on box of adobe photoshop elements 13 that I bought from amazon.  the booklet has the first four numbers and they are nowhere listed on the box.