Java variables calculation on change in JSP (Excel replica)

I have a excel sheet that I need to replicate in JSP (using struts 1 framework). Now everything is done but I am stuck at the calculation part. As you might have seen in excel, some columns are calculations based on other columns.
So if I change field 'a', 'd' field should change automatically based on its formula (let's say, d=a*1.1 +b*2.1).
Now I tried to use the funstion in javascript where I read 'a' and 'b' values from JSP, then I calculate and everything works fine. But when I try to assign the calculation result for field 'd' in JSP throush javascript, 'd' does not change.
function adjustCalcs ()
var a = eval("document.form.al.value");
var b = eval("document.form.b.value");
var dCalc = ((a * 1.05) + (b * 1.1));
document.form.d.value = dCalc ; (this is where it should change the value of field 'd' in JSP, but ti won't...donno why?)
Or is there any better way to do these dynamic changes in JSP ? Would appreciate the insight.
Thanks,

Fine. What's your problem in JSP side then? Do you want to let Java take over the calculation and "dynamic stuff" ? Then you need to let Javascript submit the form to the server side during the change event so that JSP can then display the result using taglibs/EL. But this is less good for user experience as this costs effectively one HTTP request and the user would see a "flash of content". Alternatively you can use Ajax for this to do it all asynchronously.

Similar Messages

  • How can we  use java variable in javascript code on JSP page?

    How can we use java variable in javascript code on JSP page?
    Pls help

    Think about it:
    JSP/Java is executed on the Server and produces HTML+JavaScript.
    Then that HTML+JavaScript is transfered to the client. The client now interpretes the HTML+JavaScript.
    Obviously there's no way to access a Java variable directly from JavaScript.
    What you can do, however, is write out some JavaScript that creates a JavaScript variable containing the value of your Java variable.

  • Inserting Images into Acrobat Pro Form And using java script calculation to change it

    Hi,
    I am trying to create a form witch shows text results bassed of tick boxes and I have managed to be able to do that but I need to have icons shown along side them based upon the result and I am not even sure how to input images in the first place.
    I read somewhere that I have to use the content pane but I dont have it and it is not selectable in the view options.
    Also the image I am trying to insert is .ai will it need to be .jpg or .png?
    any help would be greatly aprectiated!
    Thanks,
    Bruce

    That works the only thing is that when another one is selected it stays visible i have tried this
    this.getField("Button1").display = event.target.value=="Off" ? display.hidden : display.visible;
    this.getField("Button2").display = event.target.value=="On" ? display.hidden : display.visible;
    this.getField("Button3").display = event.target.value=="On" ? display.hidden : display.visible;
    this.getField("Button4").display = event.target.value=="On" ? display.hidden : display.visible;
    and alternated them between which one needs to work but that didnt work either, any ideas?
    Thanks,
    Bruce

  • Assign j_user value to a java variable in umLogonPage.jsp

    Hi All
    I need to do some post processing immediately after login and require the user id for the same. So how do we acess the value in the user id field and assign it to a java variable in the umLogonPage.jsp..??
    Java specific forums claim that this is not possible directly and can be only done on submit function or through hidden fields in the form. Any ideas with regard to the form that is present in umLogonPage.jsp..??
    Thanks
    Deepak

    Hi,
    we use this for saving the login time of the user. There are few therads about creating a custom login module (for example: [Custom Login Module - how to go on |http://forums.sdn.sap.com/thread.jspa?threadID=357616]).
    We have created a login module which extends AbstractLoginModule, in login() method :
    public boolean login() throws LoginException  {
    Object option = g_sharedState.get("javax.security.auth.login.name");
    if (option != null && !option.equals(""))  {
      String l_userID = (String)option;
      IUserAccount l_account = UMFactory.getUserAccountFactory().getUserAccountByLogonId(l_userID);
      IUserAccount mutableAccount = accountFactory.getMutableUserAccount(account.getUniqueID());     
      l_mutAccount.setLastSuccessfulLogonDate(new Date());
      l_mutAccount.commit();
    about login modules and login stacks start here: [http://help.sap.com/saphelp_nw04/helpdata/en/8c/f03541c6afd92be10000000a1550b0/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/8c/f03541c6afd92be10000000a1550b0/frameset.htm]
    Hope this helps,
    Romano

  • Using a java variable in jsp-Reports?

    Hello everyone,
    is it possible to use a java variable in the xml-definition of a report? Something like
    <%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="rw" %>
    <% String someSqlStatement="select * from emp"; %>
    <rw:report id="myReport">
    <rw:objects id="myObjects">
    <report DTDVersion="9000010" name="myReport">
    <data>
    <dataSource name="Q_1">
    <select>
    <![CDATA[
    <%= someSQLStatement %>
    ]]>
    </select>
    It won't work that way (as the string is not evaluated and inserted into the definition, but how could it be done? Would be great to modify the report programatically that way? Any ideas?
    TIA,
    Marcel Jantz

    To pass values to Reports, you should use the "parameters" attribute in the <rw:report> tag. In the above case you would have:
    <% String myParameters="p_someSqlStatement=select%20*%20from%20emp"; %>
    <rw:report id="myReport" parameters="<%= myParameters %>">
    <rw:objects id="myObjects">
    <report DTDVersion="9000010" name="myReport">
    <data>
    <dataSource name="Q_1">
    <select>
    <![CDATA[ &p_someSqlStatement ]]>
    </select>
    The body of the <rw:objects> tag isn't evaluated since the Reports Builder needs to be able to open and load the <rw:objects> tag. As the Reports builder doesn't run the .jsp on open, it only parses it, the <rw:objects> tag can't have values that need to be evaluated.

  • Passing a variable from Javascript to java variable in a JSP.

    Here is simple test Ive been messing around with.
    How do I assign the value that was selected in the radio button to a java variable in my JSP here. Javascript being client side and JSPs being serverside makes this difficult.
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function valbutton(thisform)
         myOption = -1;
         for (i=0; i<thisform.myradiobutton.length; i++)
              if (thisform.myradiobutton.checked)
                   myOption = i;
         if (myOption == -1)
              alert("You must select a radio button");
              return false;
         alert("You selected button number " + myOption + " which has a value of " + thisform.myradiobutton[myOption].value);
         thisform.submit();
    </SCRIPT>
    <title>CreateCategoryContent</title>
    </head>
    <body>
    <BR>
    <center>
    <%
         for(int i = 0; i < 10; i++)
    %>
    <form name="myform">
    <table border="1" bordercolor="#C0C0C0" width="50%" cellpadding="0" cellspacing="0" bgcolor="white">
         <tr>
         <td><%=i%><input type="radio" VALUE="<%=i%>" name="myradiobutton"></td>
         </tr>
    <%
    %>
    </form>
    <input type="submit" name="submitit" onclick="valbutton(myform);return false;" value="Validate" />
    </table>
    </center>
    <!--//T2-->
    </body>
    </html>
    Thanks dudes.

    Please excuse me for appearing dim but my JSP skills are rather weak.
    I dynamically create rows in a table from an Iterator. If the mainTopic is news then I need a third column to appear with radio buttons. I have all this done. When a radio button is selected and the UPLOAD button is selected I need to know which of the values in the table was selected.
    When I ran the test below the selected value was null. Can you help me?
    Thanks.
    <%@ page session="false" %>
    // imports etc
    <%@ page errorPage="../com/digisoft/common/Error.jsp" %>
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function valbutton(thisform)
         myOption = -1;
         for (i=0; i<thisform.myradiobutton.length; i++)
              if (thisform.myradiobutton.checked)
                   myOption = i;
         if (myOption == -1)
              alert("You must select a radio button");
              return false;
         alert("You selected button number " + myOption + " which has a value of " + thisform.myradiobutton[myOption].value);
    thisform.selected.value=thisform.myradiobutton[myOption].value;
         thisform.submit();
    </SCRIPT>
    <title>CreateCategoryContent</title>
    <LINK REL="stylesheet" HREF="<%=request.getContextPath() + "/stylesheets/digihostnews.css"%>" TYPE="text/css">
    <%
    HttpSession session = request.getSession(false);
    String mainTopic = request.getParameter("mainTopic");
    String subCategory = request.getParameter("subCategory");
    String subCategoryId = request.getParameter("subCategoryId");
    String subCategoryToBeDeleted = request.getParameter("subCategoryToBeDeleted");
    String selection = request.getParameter("selection");
    // other initializations etc
    %>
    </head>
    <body>
    <BR>
    <!--Another table-->
    <center>
    <table border="1" bordercolor="#C0C0C0" width="90%" cellpadding="0" cellspacing="0" bgcolor="white">
         <tr>
              <td class="blue">Select Topic</td>
         </tr>
         <tr>
         <td class="insidebox2">
         <BR>
              <form action="NewsUpdate.jsp" method=post>
              Select Topic
              <select NAME="mainTopic" class="dropdown">
              <%
                   Iterator menuItems = myLombardiaMgr.getMainCategories();
                   while(menuItems.hasNext())
                        MainCategory aMenuItemCategory = (MainCategory)menuItems.next();
                        String menuItem = aMenuItemCategory.getMainCategory();     
                        if(!menuItem.equalsIgnoreCase(mainTopic))
              %>
                        <option VALUE="<%= menuItem %>" ><%= menuItem %></option>
              <%
                        else
              %>
                        <option SELECTED VALUE="<%= menuItem %>" ><%= menuItem %></option>
              <%
              %>
         </select>
         <INPUT type=submit class="newsbutton" value="LOAD" name=Submit>
    </form>
    <form action="AddCategoryDescription.jsp" method=post>
    <INPUT TYPE=HIDDEN NAME="mainTopic" VALUE="<%=mainTopic%>">
    <INPUT type=submit class="newsbuttonlong" value="EDIT DESCRIPTION" name=Submit>
    </form>
    </td>
    </tr>
    </table>
    </center>
    <!--//Another table-->
    <!--T2-->
    <center>
    <table border="1" bordercolor="#C0C0C0" width="90%" cellpadding="0" cellspacing="0" bgcolor="white">
         <tr><td class="blue">Categories</td></tr>
         <tr>
              <td class="insidebox2">
              <BR>
              <form action="NewsUpdate.jsp" method=post>
                   Add Category
                   <input type="text" name="subCategory" class="dropdown" id="catId" value=""/>
                   <INPUT TYPE=HIDDEN NAME="mainTopic" VALUE="<%=mainTopic%>">
                   <%      
                   if (mainTopic != null)
                        %>
                        <INPUT type=submit class="newsbutton" value="ADD" name=Submit>
                   <%
                   else
              %>
                   <INPUT type=submit class="newsbutton" value="ADD" name=Submit disabled>
                   <%
                   %>
              </form>
                   <!--T3-->
         <table id="categoryTable" border="1" bordercolor="#035C98" width="60%" height="60%" cellpadding="0" cellspacing="0" bgcolor="white">
         <tr>
         <td colspan="1" class="result"><b>Category Name</b></td>
         <td colspan="1" class="result"><b></b></td>
         </tr>
    <%
              if(myApplicationDetails != null)
                   myApplicationDetails = myLombardiaMgr.getAllApplicationDetails();
                   Iterator myMainCategories = myApplicationDetails.getMainCategories();
              while(myMainCategories.hasNext())
                   MainCategory aMainCategory = (MainCategory) myMainCategories.next();
                   if(aMainCategory.getMainCategory().equalsIgnoreCase(mainTopic))
                        Iterator subTopics = aMainCategory.getSubTopics();
                        while(subTopics.hasNext())
                             SubTopic aSubTopic = (SubTopic) subTopics.next();
                   %>
                        <form action="NewsUpdate.jsp" method=post>
                             <tr>
                             <td class="result"><%=aSubTopic%></td>
                             <td class="result">
                                  <INPUT type=submit class="newsbutton" value="REMOVE" name=Submit>
                                  <INPUT TYPE=HIDDEN NAME="subCategoryId" VALUE="<%=aSubTopic.getId()%>">
                                  <INPUT TYPE=HIDDEN NAME="subCategoryToBeDeleted" VALUE="<%=aSubTopic%>">
                                  <INPUT TYPE=HIDDEN NAME="mainTopic" VALUE="<%=mainTopic%>">
                                  <INPUT TYPE=HIDDEN NAME="subCategory" VALUE="<%=aSubTopic%>">
                             </form>
                        <form action="EditStoryItem.jsp" method=post>
                             <INPUT TYPE=HIDDEN NAME="subCategory" VALUE="<%=aSubTopic%>">
                                  <INPUT TYPE=HIDDEN NAME="subCategoryId" VALUE="<%=aSubTopic.getId()%>">
                                  <INPUT TYPE=HIDDEN NAME="mainTopic" VALUE="<%=mainTopic%>">
                                  <INPUT type=submit class="newsbutton" value="EDIT" name=Submit>
                             </form>
                             <%
                                  if(mainTopic.equalsIgnoreCase("News"))
                             %>
                                  <td class="result">
                                       <INPUT type="radio" name="newsitem" VALUE="<%=aSubTopic%>" >
                                       <INPUT TYPE=HIDDEN onclick="valbutton(myform);return false;" NAME="selection" >
                                  </td>
                             <%
                             %>
                   </td>
                             </DL>
                                  </tr>
                        <%
                             } // end of if
                        %>
         </table>
         <table border="0" bordercolor="#C0C0C0" width="60%" cellpadding="0" cellspacing="0" bgcolor="white">
         <tr><td align="right">
         <form action="../../../../../../servlet/UploadXmlFiles" method=post>
         <% if(myApplicationDetails == null )
         System.out.println("******************* selection "+selection);
    %>
              <INPUT type=submit class="newsbutton" value="UPLOAD" name=Submit disabled>
    <%
         else
    %>
    <INPUT type=submit class="newsbutton" value="UPLOAD" name=Submit>
    <%
         System.out.println("******************* selection "+selection);
    %>
         </form>
         </td>
         </tr>
         </table>
         <!--//T3-->
         </td>
         </tr>
    </table>
    </center>
    <!--//T2-->
    </body>
    </html>

  • How can I assign javascript variables to jsp or java variables.?

    How can I assign javascript variables to jsp or java variables.?

    See I have generated some variables in the javascript which is on the jsp page. I want to assgin these variables to the jsp vaiables. Or how can I access javascript variables from jsp on the same jsp page.

  • Assigning javascript variables to java variables in JSP

    Does anyone know if it possible to assign a javascript value to a java variable in a javascript function? I want to be able to use the javascript value in a PreparedStatement call, but I can't assign the value of the javascript variable to a java variable. I know the opposite can be done using hidden variables in the form, but I need:
    javascript -> java variable in a JSP scriptlet.
    Any help would be much appreciated,
    Thanks,
    -Dave

    Can't do that.
    html/javascript is in the client side.
    jsp is in the server side.
    In order to put html/javascript values (client side) into jsp (server side) it must be submitted.
    Try remoting. Using an iframe with a jsp as the source of it and the html target pointing at it.
    -------------

  • Read China content in JSP and store in Java variable

    Hi All ,
    I have created China language content(BinaryType) using weblogic admin console.
    And I am trying to get the content and to store in a Java Variable .
    Pls suggest me how to read other language content and to store in java variable for manipulation.
    Srinivas
    I am using following lines of code to get content
    <utility:forEachInArray array="<%=newsID%>" id="node" type="com.bea.content.Node">
    INodeManager nodeManager =     ContentManagerFactory.getNodeManager();
         java.io.InputStream is =     nodeManager.getStream(new ContentContext(), node.getId(),
    "News-Content");
    when I am using inputstream "is" to read the china content , its displaying garbage values.

    Hi Rajeev,
    My Content consist of following properties
    News-Author      String
    News-Content      Binary
    News-Id           String
    "News-Content" is Binary Type .I am creating data for this property using Content Editor.
    My data consists of 3 lines of text+image
    data will be:
    author is srinivas
    created on 11th
    content is newscontent
    << inserted image >>
    where << inserted image >> ,is jpeg file.
    I want to read this data in the JSP and store in java variable , so that i can modify 1st two lines and updated data to be displayed in browser..
    I am able to read data , if its a simple text . But it has one image also.
    How to solve this issue.
    Srinivas

  • How to access a variable from a dynamically included JSP page

    I have a jsp (say main.jsp) using the following in its code :
    <jsp:include page="menu.jsp" flush="true" />
    I have a variable in menu.jsp which I would like to use in my main.jsp.
    How do I get the value of the variable defined in menu.jsp ?
    I called this variable in menu.jsp, Public, but this didnot help me use the value of that variable in main.jsp
    Any help is highly appreciated.. thnks a lot

    I do notice the variable var1 has the value populated - in menu.jsp - (from View -->
    Source in the browser) but for some reason not able to use it in main.jspI'm not quite sure of the way your jsps are structured from your code snippet but I think there is something to be aware of here that may be part of your problem, namely the difference between the include directive and the include action.
    You are currently using the include action, this treats the included resource as a dynamic object - i.e. a request is sent to that resource and the resulting response is included in your page. So when you think of what there is no java variable actually included - you'll just get the resulting HTML that is generated by menu.jsp
    The include directive, as in <%@include file=�menu.jsp � %>, on the other hand treats the resource as a static object. This means the actual bytes in the included resource are inserted into the including jsp and then the result of that is compiled and processed, effectively you are cutting and pasting the menu.jsp into your calling jsp. In this case the variable would be available to the calling jsp.
    However this approach does bring other difficulties that may break your current code, you'll just have to try it and see what happens.
    Hope that's relevant to your problem,
    Matt

  • Assigning javascript varibel value to java variable

    Hi all
    I want to find screen resolution in one jsp page.That can be done in javascript.
    (though 'screen.width and screen.height')
    But is there any way to assign that value to java variable.
    Any body has the idea?
    Help me.

    No, why ? becuase jsp is SERVER side
    There are workarounds, You can store your javascript values in hidden fields and submit your page with them to your JSP and then use them like that

  • Assigning javascript varible value to java variable

    Hi all
    I want to find screen resolution in one jsp page.That can be done in javascript.
    (though 'screen.width and screen.height')
    But is there any way to assign that value to java variable.
    Any body has the idea?
    Help me.

    No, why ? becuase jsp is SERVER side
    There are workarounds, You can store your javascript values in hidden fields and submit your page with them to your JSP and then use them like that

  • Changing a jsp in application

    I have a java web application that is running on Sun's web server for a few years. It consists of jsp pages. In one of the jsp pages, there is a string for database. The database location and name is changing.
    I can change the jsp page in notepad with the new database name, but how do I make it available to the application .... Do I need to compile the jsp page ?
    Thanks

    Yes, that's one use of the include directive, lets you add content inline. You missed an "@" there though. It's <%@ include...
    EDIT: One word of warning; it is not mandatory for the container to recompile the including JSPs if the included resource is changed! It seems you have a smart container which detected that your included JSP had been modified and so it's reflecting the changes in the other files too. But this is not required behaviour and so you shouldn't count on it. AFAIK, Tomcat will also do the same.
    Also, this is a good reason why, even though it seems like a good idea to put the DB URL into one JSP and include it everywhere so that you have only one entry to change when the DB changes, it's still risky. A better way would be to put it as a <context-param> or something similar.
    Edited by: nogoodatcoding on Sep 28, 2007 10:15 PM

  • Change Headings in Excell sheet in BSP Layout

    Hi,
    How to Change Headings in Excell sheet in BSP Layout?
    Thanks
    Srinivas

    Hi Anhubav,
    R/3 data sent to BW report -> excell sheet displaying in Bps layout in BSP Layout using Java script code Excell sheet layout headings are how to find out
    Thanks
    Srinivas

  • Getting Java var on second page without JSP:Forward

    Hi all ..
    My friend has asked a question....
    So
    i want to get a Java variable on the second page
    with out using Session or Jsp forwarding.
    I hav use Request Dispatcing this eork only in Jsp forwrding scheme.
    I wan to access a java variable on the submittion of first page.
    Plz guide me.
    Thanks in advance

    YoGee, I think that would still involve forwardingI don't think so. If the user posts the form from the
    first jsp ("submittion of first page") you don't need
    to do a forward.You cant pass a Vector through a form. You need to set it
    in the request and then either forward or include the 2nd
    page.. that or set it in the session or application scope
    and redirect to the next page.

Maybe you are looking for

  • CS3 Camera Raw sometimes opens, mostly not

    I recently both upgraded my Mac operating system from 10.3 to 10.4.11 and installed the new CS3. Before the upgrade and installation all raw files shot with a Canon 5D opened fine in Bridge. Now, in a completely random order, only about 20% of the ra

  • File to Soap Syn Scenario

    Hi Experts, I have created File to Soap syn Scenario. I am getting following error in RWB (CC monitoring):: SOAPFault received from Integration Server. ErrorCode/Category: XIProtocol/WRONG_VALUE; Params: SOAP:Envelope(1)SOAP:Header(1)sap:DynamicConfi

  • Manual Check - Payment Advise

    Hello friends, I issued checks manually. Now i want to generate payment advice for each one separately. Is it possible. Thanks, Rams.N

  • Starting Over with Authorizing Computers

    I have had several computers (through work and personal) over the years and made the mistake of not deauthorizing the itunes accounts upon returning the computers. I just bought a new 24" iMac which I love, but I cant play any of my authorized music

  • How to use BundleTransformer in Console Application?

    Hi, I have a scss file (style.scss) and I want to transformer it to CSS using BundleTransformer. How to do it in a Console Application? I'm looking for example code or something like that :)