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

Similar Messages

  • 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>

  • 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

  • Calling jsp file from javascript function

    How can i call a jsp file itself from javascript function written in it?

    I do not think you can invoke the current jsp directly using javascript.
    If the effect you are trying to achieve is to reload the page, then you could execute the servlet / code which called the current jsp.

  • How can i get the variable declared in jsp to a javascript function

    Hello all.
    I'm in a trouble.. i was developing a program in jsp oracle. and in some cases i use java scripts.. here in the HR program module i feel a trouble.
    the code here i'm sending is just a trial one.. the jdbc and all are doing in the jsp page itslef.
    egs.. : there is a table with 4 fields
    Empid Empname Empdetails EmpSal
    and in the table there are 100 records. Emp id is the primary key
    here what my problem starts..
    i want to list all the emp id in the combo box
    for that i used jsp program
    now when i select any one emp id i want to display the
    empname emp details and emp salary in another 3 text boxes
    i have successfully placed all the empid in the combo box
    now what i done is i wrote code in java script.. in onchange() for combo
    now i'm not getting the values
    here i'm sending the code.. below..
    please help me
    <html>
    <head>
    <title>DOLOGIN
    </title>
    </head>
    <%@ page language="java" session="true" import="java.sql.*" %>
    <body>
    <form method="POST" name="form1" action="--WEBBOT-SELF--">
         <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
    <select size="1" name="D1" onchange =xx() >
    <option> Select One</option>
    <%
    String age[] = new String[20];
    String ph[] = new String[20];
    int i=0;     
    try
         try
         {     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         catch(ClassNotFoundException e)
         {     out.println(e);
              String dbURL = "jdbc:odbc:trial";
              Connection dbCon;
              dbCon = DriverManager.getConnection(dbURL);
              String query = "Select * from table1";
              Statement stmt = dbCon.createStatement();
              ResultSet rs = stmt.executeQuery(query);
              while(rs.next())
              {     String name = rs.getString(1);
                   //out.println(name);
                   %>
                   <option value="<%=name%>"><%=name%></option>
                   <%
                   age= rs.getString(2);
                   ph[i] = rs.getString(3);
                   //out.println(age[i]);
                   //out.println(ph[i]);
                   i++;
         %>
         </select>
         <%
              out.println(age[4]);
              dbCon.close();
              stmt.close();
    catch(SQLException e)
    {     response.sendRedirect("error.html");
    %>
    </form>
    </body>
    </html>
    <SCRIPT LANGUAGE=javascript>
    <!--
    function xx()
    {     //alert("aravind")     
         alert(document.form1.D1.selectedIndex)
         alert(document.form1.D1.value)
         alert(age[document.form1.D1.selectedIndex]) //this is not executing//
    //-->
    </SCRIPT>
    here is the code..
    i want the age to run here
    please help me

    To ensure a custom ordering, sort the files in an album and rename the files with a sequentially numbered filename.
    File > Export > Version/Originals
    Then use "Filename > Sequential"
    or "Filename > Album name with index"

  • HELP MENU FUNCTION-URGENT HELP PLZ.

    Hello there. I've been trying to design a GUI providing the users with help function as well. I create the html file, map file(in .jhm format) and HelpSet (in .hs format) and run the help menu via hsviewer. The first problem is that when the hsviewer runs the application a blank help window appears on the screen. The second one is that when I try to make a link between the help menu and the GUI I have written by using the sample code given in javahelp's pdf file I see a few error messages on NETBEANS' screen. Could anyone help me solve the problems I have faced so far? In addition, aint there any other method, like a template help menu, that I could use to compose my own one?

    * stop multi-posting
    * stop SHOUTING
    * whenever you see error messages and have some problem, those two are probably related
    * whenever you ask for help and have error messages post the error messages!

  • JButton as TAB function : Urgent Help

    Hi people, pls i need some help... I have an interface that displays html pages in a JEditorPane. I want to be able to tab within the html page displayed in the jeditorpane and outside the jeditorpane to the other button components using my own JButton titled "Next".
    Any ideas about the general logic? im probably going to override some ismanagingfocus() functions, etc, but i need to understand the logic first
    do i create an function (e.g tabAction() and call like:
    myTabButton = new JButton("Tab")
    myTabButton.addActionListener(tabAction())
    and in this function, create a keystroke using KeyEvent.VK_TAB?
    Input will be greatly appreciated
    thanks

    * stop multi-posting
    * stop SHOUTING
    * whenever you see error messages and have some problem, those two are probably related
    * whenever you ask for help and have error messages post the error messages!

  • JSP for Printer Friendly Version - urgent help

    Hi all,
    I have a JSP web application to collect student's homework. It needs to render the webpage to a printer friendly version with custom headings for easy print out by the teachers. The different submission should be printed out on seperate pages, but since the length of each homework is different, I cannot find a better way to reach the goal. Does any one have any ideas about this?
    Any input would be highly appreciated!
    Thanks.

    Yes, it's such a shame. If it hadn't been an urgent question there might have been some point in my answering it. Obviously too late now though...

  • Pass a para to javascript function

    In a jsp page, a javascript function needs to get a parameter from a variable of the jsp page. How can I do this? Thanks a lot!
    ---a.jsp---
    <SCRIPT language=JavaScript>
    function changeR(userID){
    alert( userID + " chaged a value " );
    </SCRIPT>
    <% userID = "user1" %>
    <form>
    <input type="button" value="bbbb" onclick="changeR(userID)"> <!--it doesn't work this way-->
    </form>
    How should I write this part?
    onclick="changeR(??????)"

    <%! String userID=""; %>
    <html>
    <head>
    <script type="text/javascript">
    function changeR(userID){
    alert( userID + " chaged a value." );     // this line doesn't work.
    alert( "alert" );          // even this line doesn't work either.
    </script>
    </head>
    <body>
    <% userID = "user1"; %>
    <form>
    <input type="button" value="<%= userID %>" onclick="changeR(<%= userID %>)"> <!--it doesn't work this way-->
    <input type="button" value="userID" onclick="changeR(userID)"> <!--it doesn't work this way-->
    </form>
    </body>
    </html>
    This is the sample jsp page. There are two ways tried (two buttons), none of them works. :(
    When the first button is pushed, there's no response.
    When the second button is pushed, the status bar shows "Script Error!".

  • Help needed in calling a javascript function from a jsp

    Hey guys,
    I need help.
    In my jsp I have a field called date. When i get date field from the database, it is a concatination of date and time field, so I wrote a small javascript function to strip just the date part from this date and time value.
    The javascript function is
    function formatDate(fieldName)
              var timer=fieldName;
              timer = timer.substring(5,7)+"/"+timer.substring(8,10)+"/"+timer.substring(0,4);
              return timer;
    Now I want to call this javascript function from the input tag in jsp where I am displaying the value of date. Check below
    This is one way I tried to do:
    <input size="13" name="startDate" maxLength="255" value=<script>formatDate("<%=startDate%>")</script> onChange="checkDate(this)">
    I even tried this:
    <input size="13" name="startDate" maxLength="255" value="'formatDate(<%=startDate%>)'" onChange="checkDate(this)">
    But it dosen't work
    Please help. I am struggling on this for days.
    Thanks,
    Ruby

    Hey all you developers out there , Pleaseeee help me with this one.

  • CFloop in Javascript function...pls help urgent

    <script type="text/Javascript">
          function XYZ(group_id)
           switch(group_id)
            <cfloop query = "GetProgramAuthGrpRouting">
             case '#GetProgramAuthGrpRouting.group_id#':
              <cfset variables.user_names = "">
              <!--- Get all users belonging to the selected group id --->
              <cfquery name="GetGroupUsers" datasource="#request.db_instance#">
               select distinct employee_number from dbo.DIV_USER_GROUP_XREF where division =
                <cfqueryPARAM value = "#request.Pub.Project.division#"> and group_id =
                <cfqueryPARAM value = "#GetProgramAuthGrpRouting.group_id#">
              </cfquery>
              <!--- Getting the name of the user by passing the employee id to the GetUser custom tag  --->
              <cfif GetGroupUsers.RecordCount gt 0>
               <cfloop query = "GetGroupUsers">
                <CF_GetUser
                 query_name = "GetUser"
                 employee_number = "#GetGroupUsers.employee_number#">
                <cfset variables.user_names = variables.user_names&''&GetUser.employee_name&'\n'>
               </cfloop>
              <cfelse>
               <cfset variables.user_names = 'No users in this routing group\n'>
              </cfif>
                alert('#variables.user_names#');
                break;
              </cfloop>
         </script>
    Hi all I am new to this community and this is my first post here. So if this is the wrong place for these then pls let me know the right area. Thanks.I have looped over the result set using CFLOOP in  javascript function and it is working fine. But I want to know if this can be done since javascript is a client side scripting language and CF is a server side. Is this the right way of coding? Can i use cfloop in a javascript function? Please help me as this is urgent. Thanks in advance.

    You you can use CFML inside of a JavaScript <script..> block to dynamically build the JavaScript code to send to the client.  It is a very powerful technique for building highly interactive web sites.
    Just realize that all the JavaScript code is going to be completely built by the CFML and then sent to the browser client through the web server where the JavaScript is executed completely independent of anything that is running on the server.  The JavaScript can not read or write variables on the server or vice-a-versa.  But it is quite easy to export variable values from ColdFusion to JavaScript.  It is a bit more work to export variable values back requiring either the browser or JavaScript to make a new request of the server to send the data.  AJAX does allow this to happen behind the scenes making it look like the data is being shared.  But in reality it is being passed back and forth with independent HTTP requests and responses.
    A recent discussion on this topic:
    http://forums.adobe.com/message/1957350#1957350

  • How to get value stored in  javascript function and display in a JSP

    i am doing a questionaire which is for user to input data in every question, After user input the data, a javascript function will be called to do some score calculation. Since each question will carry its final score after the calculation by the javascript function, so i use an array to store those scores and then display those scores in the same page.
    However, i have to make a confirmation page to display both data and calculated score in another jsp, i only know how to display the data as it is a textfield that i can get the value by "request.getParameter("textfield1"); but i dun know how to get those scores as they are stored in an array in the javascript function, what way i can do??

    thank you for all your help!
    I have chosen to set the score value to the hidden field when every time run the function
    <script language="javascript">
    function cal(index){
    var thisForm = document.MC;
    thisForm.score1.value=score[index];//set value to the hidden field     
    </script>
    <input type="hidden" name="score1" value="">
    <input type="hidden" name="score2" value="">
    <input type="hidden" name="score3" value="">
    The function will calculate only one score when every time being called. So that i can only assign one score to one hidden value at a time.
    e.g, assign score[1] to thisForm.score1.value
    assign score[2] to thisForm.score2.value
    assign score[3] to thisForm.score3.value
    how can i do this??

  • How to fill a javascript array by a jsp array when the jsp is run

    Hi all,
    The problem i am facing is -- i want to use an javascript array in a function. The records are being fetched by jsp.
    How to fill the vaules in a javascript array, which are retrieved by a jsp array
    Please suggest
    Thanking You

    You can use the code below:
    <input type="button" value="Click Me" onclick="javascript:disp('<%= getString(str) %>')">
    <%!
    public String getString(String str[]){
    String arrElements="";
    for(int i=0;i<str.length;i++) {
    arrElements+=str[i]+",";
    return arrElements.substring(0,arrElements.length()-1);
    %>
    function disp(str) {
    arr = str.split(",");
    alert ("There are "+arr.length+" elements in the array");
    Hope this helps.

  • How to put a jsp variable into a javascript function?

    Please read the following coding. I want to pass the variable ans from jsp to the function check_answer() of javascript. ans is a string got from database. But I cannot put the variable ans into the Javascript function. Can anyone help?
    <script language="Javascript">
    function check_answer() {
    if (testing.result.value==ans ){
    window.alert("You have got 10 marks.");
    </script>
    <body>
    <form name="testing"...>
    <%
    ResultSet rs = stmt.executeQuery("select * from level where...");
    while(rs.next())
    out.println("<tr>");
    out.println("<td>" + rs.getString("question") + "</td>");
    ans = rs.getString("answer");
    out.println("</tr>");
    out.println("<input type='text' name='result'>);
    out.println("<input type='button' value='Enter' onclick='check_answer()'>");
    %>

    The following should be able to pass ans.
    <script language="Javascript">
    function check_answer(ans) {
    if (testing.result.value==ans ){
    window.alert("You have got 10 marks.");
    </script>
    <body>
    <form name="testing"...>
    <%
    ResultSet rs = stmt.executeQuery("select * from level where...");
    while(rs.next())
    out.println("<tr>");
    out.println("<td>" + rs.getString("question") + "</td>");
    ans = rs.getString("answer");
    out.println("</tr>");
    out.println("<input type='text' name='result'>);
    out.println("<input type='button' value='Enter' onclick='check_answer('<%= ans%>')'>");
    %>jag

  • How to return javascript function value to jsp page

    Hi i want to retrieve values from javascript function to jsp page, how can i do that ? i am trying this but its not working
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
    <td>
    <jsp:param id="description" value= "<%=request.initRTE('', '')%>"/>
    </td>
    here this initRTE function is used for displaying rich text editor .....i want to retrieve back the contetnt written in this editor and save it to DB.
    Please help.
    Edited by: xtech on Apr 4, 2008 12:00 PM

    surely i will do that but my app is still not working.....
    here is my code
    </td>
    <td align="left">
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
    <script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
    <h:inputHidden id="introtext" value= "<%=request.getParameterValues(description)%>">
    <script>
    initRTE('','');
    </script>
    </td>
    in java script function i am geeting the text content
    function initRTE(rtePreloadContent, rteCSS) {
    rtePreloadContent=document.getElementById('surveyinfo:introtext').value;
    startRTE(rtePreloadContent);
    menuBuilder();
    var description= document.getElementById(rteFormName).value;
    return description;
    basically i want to get the text written in text editor in jsp and want to send it to DB.(Here initRTE() function is calling rich text editor)
    i have downloaded this editor from this url
    http://freerichtexteditor.com/page/4.htm
    and trying to embed it in my app.

Maybe you are looking for