Parsing JSP values on to javascript functions

HI
Is it possible for Javascript functions to accept JSP variables?
For instance:
<script language="Javascript">
function selectEdit(fileID) {
   document.forms[0].recordID.value = fileID;
   document.forms[0].submit();
     </script> and a button calls the method like this:
   <input type="submit" name="Submit" value="View" onClick="selectEdit('<%= Record %>'")> I tried but was unsuccessful, can someone help?
Thanks
Eugene

Lets say you use your JSP to generate a set of links
page1.jsp:
<form target="targetPage.jsp">
<input type="hidden name="recordId");
<% for (int record=0; record<10; record++){  %>
  <input type="submit" name="Submit" value="View" onClick="selectEdit('<%= record %>')">
<%  }  %>
</form>This JSP code runs, and generates the following
<form target="targetPage.jsp">
<input type="hidden name="recordId");
<input type="submit" name="Submit" value="View" onClick="selectEdit('0')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('1')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('2')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('3')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('4')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('5')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('6')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('7')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('8')">
<input type="submit" name="Submit" value="View" onClick="selectEdit('9')">
</form>This gets sent to your browser on displayed on screen
When you click on the appropriate button, it calls your function selectEdit, which sets the value of the hidden field according to which button you pushed.
It then submits the form, to targetPage.jsp
targetPage.jsp retreives the value using request.getParameter("recordId");
which is the name of the hidden field being submitted.
JSP reacts to form submissions, and produces an HTML page.
The HTML page can then run java script
JSP gets run again when you submit the form.
Hope this helps,
evnafets

Similar Messages

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

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

  • Assigning return value of a javascript function to a variable

    hi.
    I have a javascript function which returns string.
    I wanna assing return value of that function to variable.
    for example:
    <script>
    funtion writeMe()
    var ex;
    ex="try"
    return ex;
    </script>
    Then in body of JSP page. I wanna do something like:
    <% String st;%>
    Now I wanna assign the value that returned from writeMe function ("try") to st string.like:
    <%st= writeMe();%>. but of course it doesn't work. how can I do that?

    thnx. but actually what I want to do is sending some values produced by javascript to a barchart object. is it impossible too?
    I mean my script function returns something like "100, 200, 300". I wanna pass that values to barchart. when I want to add aplet tag to jsp code instead of writing:
    <param name="s1_value" value="100,200,300">
    I want to write somethin like:
    <param name="s1_value" value="myscriptfunction()">
    is it possible in JSP? I saw an example like this in asp. it was like:
    <param name="sampleLabels" value="<%call func1()>">. but in JSP it seems like call tag doesn't work. Is it possible in JSP?

  • 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

  • Value Passing using JavaScript function portalpagenav

    Hi,
    We have used Java script to pass two values from one report to another report.
    Ex : Country , type are the columns which we have to pass it to other report.If you click country column it should pass only country value,have given javascript in country column to go to report 1 and if you click type column then it should pass both country and type value,have given javascript in type column to go to report 2.
    I m passing the values via variables so need to declare the variables in the corresponding column.So, we have taken country and type column again in the critriea to declare the variables, we have done with this,but the problem is we wanted to hide those extra columns in the report when we download in to excel and others.
    Regards,
    Murali

    If the user makes a change to the content of the form, and then attempts to leave the form, a javascript alert pops up giving the user the option of cancelling the submit, returning to the form and saving it.
    If there have been no changes, then the user is free to migrate to another page.
    This process is to protect users from losing valuable information but not to annoy them with "R U Sure" messages.
    Knowing the status of the form content is important to the functionality of the application.
    G

  • How to pass a binding value to a Javascript function?

    Hi, I have this:
    A binding: #{bindings.DOCUMENT_ID.inputValue}
    A javascript inserted into the page in this way:
    <af:commandButton text="Ver Documento" id="cb1"
    icon="/Images/Document-Preview-icon.png">
    <af:clientListener method="openViewer('#{bindings.DOCUMENT_ID.inputValue}')"
    type="click"/>
    <af:resource type="javascript" source="/openViewer.js"/>
    </af:commandButton>
    But doing this generates this error: Error(44,34): Static attribute must be a String literal, its illegal to specify an expression.
    Any suggestions?
    Thanks in advance.

    First solution doesn't work:
    OracleJSP error: oracle.jsp.parse.JspParseException:
    /PantallaSup.jspx: Line # 45, <af:clientListener method="openViewer('${bindings.DOCUMENT_ID.inputValue}')" type="click" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"/>
    Error: Expression Language not supported in compile time attribute method

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

  • How to pass Application Item value in Javascript function.

    Hi,
    I have the following javascript in the HTML Form Element Attributes properties
    I am on Page1 and passing P1_DEPT_NO page item value. This is working perferctly fine and I am able to get the exact value of the page item
    onchange="javascript:function1($x('P1_DEPT_NO').value);"I am on Page1 and passing Application Item G_DEPT_NO value.
    The problem here is, I am not getting the Application item value inside the javascript function.
    I tried using alert(); and it's giving me value as undefined
    onchange="javascript:function1($x('G_DEPT_NO').value);"Just want to know, how to pass the Application Item value in Javascript.
    Thanks,
    Deepak

    Deepak,
    I am not an expert at Javascript, but the suggestin I made was because javascript is a case-sensitive language.. and therefore onChange is not the same as onchange.
    Not quite sure if that is causing the problem.
    Application items are not associated with a page and therefore have no user interface properties.
    Therefore, as mentioned in another post, the rendering would not work for application items.
    If it is for a single item, used only in this page, you could create a hidden page item and use it fo your purpose
    If you still want to look at application items and AJAX, This page contains examples of using AJAX to solve problems like the one you mentioned.
    http://www.oracle.com/technology/obe/hol08/apexweb20/ajax_otn.htm#t1b
    Thanks,
    Rajesh.

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

  • Javascript function not working

    Hi I am new in development.
    Could you tel me what problem may be in my jsp code.
    previously my .jsp file have some javascript functions all was working properly. Now i have made changes on one function which was working properly but now it is not working and the after clicking the button to which it is associated no action is taking place. .What may be the problem
    Thanks with regards

    The problem would be that you have introduced a syntax/runtime error into your javascript code with your changes.
    Unfortunately my mind reading powers are not working today, so I can't tell you exactly which line of code it is that you have broken.
    Maybe if you posted some code? (note I say some and not all) If you paste your whole page here unformatted, don't expect any help.
    Debugging javascript is not a nice thing to do.
    Try getting Mozilla/Firefox - it has a javascript debugger integrated with it.
    Myself I normally go along the lines of alert("step1") alert("step2") peppered through the javascript code. At the point the alerts stop, is where I focus my attention to find the error.
    Good luck,
    evnafets

  • Dynamicly change SelectOneRadio value in java script function -- Please hel

    Hello, I need to change SelectOneRadio value within a javascript function. But it doesn't seem to work for me. Can someone tall me what I did wrong or how to get this?
    Thanks a lot!
    I have :
    <h:panelGrid Columns="3">
    <h:selectOneRadio id="myRadio", value="#{myBean.radioOption}" />
         <f:selectItems value="#{myBean.radioOptionList}" />
    </h:selectOneRadio>
    </h:panelGrid>
    <script >
    function needToChangeRadioValue(choice){
    if ( choice == something ) { 
         document.getElementById("myForm:myRadio").value="1"; //doesn't really work
         document.getElementById("myForm:myRadio").immediate="true";
    } else if ( choice == somethingelse ) {
         document.getElementById("myForm:myRadio").value="2"; //doesn't really work
         document.getElementById("myForm:myRadio").immediate="true";
    } else {
         document.getElementById("myForm:myRadio").value="3"; //doesn't really work
         document.getElementById("myForm:myRadio").immediate="true";
    </script>
    -- java --
    ArrayList radioOptionList;
    public ArrayList getRadioOptionList(){
         radioOptionList = new ArrayList();
         radioOptionList.put("1","Option1");
         radioOptionList.put("2","Option2");
         radioOptionList.put("3","Option3");
         return radioOptionList;
    }

    Thank you for the quick response!
    Does it work for you? I tryed getElementsByName("myform:myRadio")[1].value="1"; No errors but the screen doesn't show that radio button is "on". I also created another function to go through the form object and try to set the attribute but no luck. From screen, I still don't see the option is selected(or on). I have :
    <script .... >
    function checkRadioButton(){
    var allElem = document.forms['myform'].elements;
    for ( i=0 ; i< allElem.length; i++ ){
    alert("element name = " + allElem.name ); // I see myform:myRadio three times
    alert("element id = " + allElem[i].id ) // when name="myform:myRadio, id is null/empty
    alert("element value = "+ allElem[i].value ); // when name="myform:myRadio, value = 1, 2, 3 respectively
    if ( allElem[i].name == 'myform.myRadio' ) {
         var attributes = allElem[i].attributes;
    for ( j =0; j < attributes.length; j++) {
              if ( attributes[j].name == 'CHECKED' ) { // I found CHECKED is one of selectOneRadio's attributes
                   if ( i == 1) {
         attributes[j].value = true; // It still doesn't work. I didn't see that option1 get selected/on.
    What I am trying to do is common, I think !!?? Really appreciate your help.

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

  • How to pass value from Javascript function to JSP ?

    hi,
    hello i have 2 jsp page and one external javascript page.
    from page 1.jsp
    i am calling a fuction named fun(1).and i am passing that value to external
    javascript page
    from external javascript.js
    i am getting this value in the fun(w) and sending this Page2.jsp like this
    var url = "page2.jsp?id ="+w;
    http.open("get","page2.jsp?id ="+w );
    and in page2.jsp
    i am getting that value like
    String k = request.getParameter("w");
    but this is showing error. how cloud i get that value on this page2.jsp ?
    plz any one help me to study this
    regards
    Vishnu Sankar S

    hello sir
    thank u very much..i got the output
    Message was edited by:
    vishnu_shankar

  • How to pass value to pop up window using javascript function?

    I am not sure how to do this, I want to open new window from existing form,This is Mod/PLsql for consists some javascript functions also. When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page :( , not able to get text box value from parent form. How to call textbox input value in popup window from parent window using javascript?
    currently I'm using following code:
    HTP.p('<script type="text/javascript">
    function pop_up5()
    var l_url=window.opener.document.getElementById("p_single_store_pc").value;
    window.open(l_url, '''', ''fullscreen=no, scrollbars=1'');
    </script>' );
    Edited by: user11970612 on Jun 14, 2012 5:02 AM

    this is probably due to the Javascript code and not a "real link" to another page... I don't know if the null is due to the Javascript...
    But if you really really want to use javascript instead of a ... you can pass the location of the url with JSP (on your main page) as a parameter to the open window... (...) u can put instead of main.jsp <%= request.getServerName()+request.getRequestURI() %>
    the value <%= ... %> will return something like test.com/html/main.jsp
    Hope this helps.

Maybe you are looking for

  • Check boxes in Data grid

    Hi, I have check boxes in data grid, using action script how do i get the values of check boxes that were selected ? Can anybody guide me here. <mx:DataGrid id="targetBaseAdd" width="100%" height="100%" dataProvider=" {Application.application.ccModel

  • Disk utilily

    I just ran "verify disk" on my startup drive and it came back with errors found and needed to be repaired. The authorization box came up where I am suppose to enter my password to continue, but I quit the program to find out if this is o.k.? Everythi

  • Purchased movie on Window, trying to view on Mac

    I purchased a movie on my itunes account at work (windows)and I'm trying to finish watching it at home on my Mac.  It shows up in my account that I've purchased it but it's not showing up in my downloads.  How can I finish watching the movie at home

  • Display changes done for reservation

    Hi Guys I have client requirement as below They  need to view changes done for reservation Can any boy help on this Thanks in Advance SAP MM

  • Wher can I find the 8.1.7.2 patch for the Sun OS 5.8

    I need to find the patch for the Oracle 8.1.7.0 to take it to 8.1.7.2 and it is running on Sun Solaris 5.8. I have looked through the Oracle site but haven't found anything that looks viable. Thanks Ted