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>

Similar Messages

  • Passing variable from javascript to servlet!!!

    Hi all,
    I have one doubt,
    can we pass a variable from javascript to servlet???
    In Brief,
    i am getting some values in javascript through jsp and the same values i
    want to use in servlet.
    Yes, i know i can get these values in servlet by using request.getParameter("");
    But these values are dynamically generated so i dont know how many varaible are they!. so i am trying to put some array list so that i can forward this values to servlet.
    But i can't get this array which is declared in javascript!! :( so any buddy can help me how to get this dynamically generated values in servlet!!!
    Thanks in Advance!! :)

    can you post a sample of your code?
    remember to put it between tags                                                                                                                                                                                       

  • Pass a table from my webdynpro JAVA application to an RFC in R/3

    Hi All,
    I need to Pass a table from my webdynpro JAVA application to an RFC in R/3. How can I do that?
    Regards
    Sarath

    Hi,
    Please have a look at this thread,
    Pass Table as Input to Adaptive RFC
    Regards,
    Saravanan K

  • Keep getting a message from Javascript (not Java)- "Uninstall Set", help it will not go away

    Each time I use Firefox, the message "Uninstall Set" keep popping up from Javascript (not Java). I can not use Firefox because this keeps popping up.

    That would be from an extension, anything similar from Firefox would have been cleaned up. If you'd been on 4.0.1 for a while and it just started happening, then I'd try Tools > Add-ons > Extensions then on the gear wheel choose "View Recent Updates" the date will appear the list small and the. The "last updated" button near top right does something mysterious.
    To see list in normal fashion again choose "Appearances" then return to "Extensions".
    If you dislike the formatting of the Add-ons list during normal viewing you can improve it tremendously with a custom style:
    * [https://addons.mozilla.org/firefox/addon/stylish/ Stylish :: Add-ons for Firefox]
    * [http://userstyles.org/styles/42112/firefox-4-compact-addons-manager Firefox 4 - Compact Addons Manager - Themes and Skins for browser - userstyles.org]
    From the wording the message could possible be referring to a Collection of Extensions. I avoid collection sets like the plague.
    Also see related answer
    * [https://support.mozilla.com/en-US/questions/824098 i keep getting a pop up saying uninstall set | Firefox Support Forum | Firefox Help] by Cor-el.

  • Passing Variables From PHP to Java Applet ?

    I took one page of a project which was written entirely in PHP, and translated it into a JAVA applet, so as to support better GUI funcitonalities (immediate calculation and display of Time/Billing data, on LostFocus events...stuff like this).
    In any case - I need to pass four variables from the php scripts, to the Java Applet. I had initially, written them out from the php scripts to an html file on the server, and read them in from the applet doing something like this:
    .     this.m_TheURL = new URL(url);
         InputStream in = m_TheURL.openStream();
         DataInputStream data = new DataInputStream(new BufferedInputStream(in));
         while ((unparsed = data.readLine()) != null)
    // parsed the strings here and got my variables
    The URL I read from, was the same file I wrote out to from the PHP scripts. This worked fine - until I told my boss about it, and realised that this wasnt going to work - because the applet updates a MySql database, and issues regarding multiple users became apparent.
    The Applet has to get these variables from the previous PHP page, the same way it had - before my applet was an applet, and it was just another PHP script page.
    The PHP pages are passing variabes using CGI, and a PostGet function. My applet has to do the same thing.
    Anybody know how I can do this - safely ?

    Updated some code... in case people wanted to use it....
    <?php
    class JavaApplet {
         var $param;
         function setParam($name, $value) {
              $temp1 =  array("name" => $name, "value" => $value);
              $this->param = array_merge($this->param, $temp1);
         function delParam($name) {
             foreach ($this->param as $key => $value) {
                  if ($key = $name) {
                       unset( $this->param["$id"]);
         function echo_html() {
              echo '<applet code=TimeEntry.class width=600 height=90 >';
              foreach ($this->param as $value) {
                   foreach ($value as $key => $value2) {
                        echo '<param name="' . $key . '" value="' . $value2 . '">';
              echo '</applet>';
    $applet = &New JavaApplet;
    $applet->setParam("name1", "value");
    $applet->setParam("name2", "value");
    $applet->setParam("name3", "value");
    $applet->echo_html();
    ?>

  • Passing a variable from html to java

    I'm trying to pass a value from a coldfusion page to an applet.
    Thanks

    I'm trying to pass a value from a coldfusion page to
    an applet.
    ThanksGood luck! So what part of the code is the problem, or what exactly is your question?

  • Passing complex object from JavaScript to Flex

    Is it possible to call a Flex function (defined with ExternalInterface.addCallback) and pass a complex object from Javascript?  The properties of the object are all simple types, but the object itself is an array of objects.  For example:
    <script type="text/javascript">
    var arrayOfObj = [ { one: "one", two: 2, three: "blah" }, { one: "xyz", two: "abc", three: 3.141 } ];
    callSomeFunctionInFlex(arrayOfObj);
    </script>
    What would I do on the Flex side to make this happen?

    Complex object passing works as expected in Blazeds. 
    There are certain cases where you need to write custom bean proxy classes to marshall an object, but your case is very simple and will not require it.
    Make sure that you set the full java package and class name in your remote alias statement on your client value object.  The class has to be fully qualified.  The AS value object also needs the correct import of the nested value object or you will get a compile error.
    Make sure that the blazeds server has the full class path set to your java objects.
    To debug, you can turn on Blazeds logging in the services-config.xml file like this:
       <logging>
            <!-- You may also use flex.messaging.log.ServletLogTarget -->
            <target class="flex.messaging.log.ConsoleTarget" level="DEBUG">
                <properties>
                    <prefix>[BlazeDS]</prefix>
                    <includeDate>false</includeDate>
                    <includeTime>false</includeTime>
                    <includeLevel>true</includeLevel>
                    <includeCategory>false</includeCategory>
                </properties>
            </target>
        </logging>

  • Remove variable from "Sequence of entry variables"

    Hi All,
    I removed a characteristic from the "free characteristic section", this characteristic has the following variable defined:
    -Type of variable: Characteristic value
    -Processing by: User Entry/Default Value
    -Variable represents: Selection option
    -Variable entry is: Optional
    "Ready for input" and "Can be changed in qry navigation" are both checked.
    From my understanding when you remove a characteristic from the query definition, the variables will be removed as well (please correct me if I'm wrong).
    In this case the input variable remains in the "Sequence of entry variables" list on the "Generic" tab of the query properties.
    I would like to remove the variable from the entry screen.
    Any suggestions?
    Thank you in advance.
    Kind regards,
    JB

    Thank you again.
    The decision is to modify (or delete) the variable which has an impact on all RFK's also if used in other queries build on this infoprovider.
    Thank you all for the quick reply.
    Kind regards,
    JB

  • Passing Variable from Javascript to Controller

    Hi Experts,
         I was using the Pagefragment page eg. CreateSales.htm. and for the leftnavigation I am using a javascript file. The scenerio was
    when user click on the left navigation "CreateSales" I was using the link eg.
    http://testserver.kuldeep.com:8440/sap/bc/bsp/zapplication/CreateSales.htm?gv_page_mode=f
    Here I am passing the variable gv_page_mode=f.
    But the page is changed into the Controller and views so I am not able to pass the variable like this
    http://testserver.kuldeep.com:8440/sap/bc/bsp/zapplication/CreateSales.do?gv_page_mode=f
    Can you please suggest me the solution. How to pass this variable gv_page_mode using the javascript into the controller CreateSales.do?
    Thanks and regards
    Kuldeep Verma

    Check the answer by Raja T in this thread
    Re: Call view in new window

  • How to get variable from javascript to jsp

    Hi,
    I put a JSP page but in one frame it has a JAVAScript running. The Javascript is a viewer that user can input bounding coordinate and see updated results. Once user input the bounding coordinate in the javascript, I would like to make
    that variable available to the entire JSP, so I can submit all query (include the parameter user input in the JSP form) from jsp at a time. How to do this?
    Thanks
    Kenny

    Hi,
    Okey here is the code. There are three frames.
    1. KennyFrame.htm
    2. MapFrame.htm
    3. kenny.jsp
    Once you run the "KennyFrame.htm" it will show a page
    with two top-bottom frames. The top is
    "MapFrame.htm".
    The bottom is "kenny.jsp"
    Once user input something on MapFrame.htm, it will do
    a process in Javascript then update the "new answer".
    I will need to put that "new answer" into the "What's
    mapFrame Input? " Text box. Therefore, when user click
    on submit on kenny.jsp frame. The "new answer" will be
    submitted.
    Code:
    MapFrame.htm (the main page)
    <body bgcolor="#FFFFFF" text="#000000">
    Newmapframe
    <center>
    <form name=form>
    <input type=text name=box value="type in here!">
    <input type=button value="Convert"
    onClick="javascript:changeCase(this.form.box)">
    </form>
    </center>
    </body>
    </html>
    MapFrame.htm (the code with javascript on top frame)
    <html>
    <head>
    <title>Map Frame Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function changeCase(frmObj) {
    var tmpStr;
    tmpStr = "Some answer!";
    frmObj.value = tmpStr;
    // End -->
    </script>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    Newmapframe
    <center>
    <form name=form>
    <input type=text name=box value="type in here!">
    <input type=button value="Convert"
    onClick="javascript:changeCase(this.form.box)">
    </form>
    </center>
    </body>
    </html>
    kenny.jsp (jsp on bottom frame for final submit)
    <html>
    <head><title>Number Test</title></head>
    <body bgcolor="white">
    <font size=4>
    <form method=get>
    What's mapFrame Input? <input type=text name=guess>
    <input type=submit value="Submit">
    </form>
    </font>
    </body>
    </html>
    let us the say the name of the frame in which kenny.jsp is placed be 'kennyframe' and u change the javascript function 'changeCase()' in MapFrame.htm to below:
    function changeCase(frmObj)
    var tmpStr;
    tmpStr = "Some answer!";
    frmObj.value = tmpStr;
    parent.frames["kennyframe"].document.form.guess.value = frmObj.value;

  • Access private variables from javascript

    Hi.
    How can i access my objects and varibles, in my java code from my javascript.

    Try displaying the value before you assign it.
    If you wanna display the value of a text field called textCallClass, this is the javascript code:
    alert(document.getElementById("form1:textCallClass").value);
    And if you wanna display a field called uniqueNum from a page called
    SchemeHolders, this is the javacsript code:
    alert(#{SchemeHolders.uniqueNum});
    You have ro have a public function called getUniqueNum in SchemeHolders.java. And ensure the case is exactly like mine is.
    That does work fine in my programs, if you have any other problems, post the error message.

  • Passing Opaque Objects from Oracle to Java

    Hi all
    I am trying to write a stored procedure that needs to be called from different triggers. Each triggers needs to pass a different set of data to the stored procedure. Now the problem is that i need to pack the different set of data into one opaque object type that i can pass onto java. Is there any way of doing this. I am using Oracle 9i running on Linux 2.4.9. I tried using the Object datatype in Oracle 9i. But am not able to pass a object datatype to java directly.

    Didn't know that. Guess the way this API handles the struct is it puts it on the heap, since this idea (with passing a 32-bit var back and forth with a memory location) worked.
    My next problem - I can't figure out a way to destroy a jstring: whenever I do an env->GetStringUTF((char*)charBuff), it seems to simply copy the bytes from the buffer
    into the same String object up the length of the buff (so I get the extra bytes from the previous String if it was longer at the end).
    Here's how it works: I have a loop in C code that parses tags inside a file, then depending on what tag it is, I create a new jobject and call a Java method to do stuff
    to that object. As one of the parameters in the constructor I pass in a String that I create (as you can see above) from a character array, however I am getting
    massive artifacts when I print out that String inside the Java method.
    Thoughts? :(

  • Drawing a Christmas tree w/ nested for loops and from JavaScript to Java

    I need help in making this code compatible with Java (I use BlueJ):
    It's JavaScript...
    Thanks in advance!
    <HTML>
    <BODY>
    <CENTER>
    <SCRIPT>
    var width=1;
    for (i=0; i <= 5 ; i++)
    for (x=0; x<=4; x++)
    for (y=1; y<=width; y++)
    var Number=Math.random()*10;
    var Ornament=Math.round(Number);
    if (Ornament<=1)
    document.write("O");
    if (Ornament>=2)
    document.write(" X");
    document.write("<BR>");
    width=width+1;
    width=width-2;
    </SCRIPT>
    </CENTER>
    </BODY>
    </HTML>

    What do you mean "compatible with Java"? Java doesn't enter into this at all.
    Are you asking how to translate this code to Java?
    If so, where you have "<BR>", you'll want a println rather than a print (as in System.out.print).
    The second tricky part is centering. The browser handled that for you here.
    You'll have to either do it yourself, or find another Java API tool to do it for you.
    If I were you I'd look at the API docs for PrintStream.format(), I think it is. It's possible that the %s conversion has a "center" option. Or maybe something else there does.
    If there is no textual centering tool, you can build one yourself by using StringBuffer or StringBuilder and padding with spaces, I guess.
    Otherwise it should map across pretty easily.

  • Communication from Javascript to Java

    I generate a html file by Java, I would like to add one button in this html page so that java program can listen to these buttons to do something else.
    So javascript could realize this fonctionaly, but how to communicate this javascript to my java program, how to fire an event when the button is pressed?
    Any help or suggestion will be appreciated. Thanks
    This is the piece of code to add a button, I think we should add something onto it...
    <html>
    <head>
    <script type="text/javascript">
    function myfunction()
    alert("HELLO")
    </script>
    </head>
    <body>
    <form>
    <input type="button"
    onclick="myfunction()"
    value="Call function">
    </form>
    <p>By pressing the button, a function will be called. The function will alert a message.</p>
    ...//the body
    </body>
    </html>

    If you have an Applet on your page with a public method called buttonClicked, you can do something like this:
    <html>
        <head>
            <script type="text/javascript">
                function myfunction() {
                    alert("HELLO");
                    document.applets["myApplet"].buttonClicked();
                    //or document.applets.myApplet.buttonClicked();
                    //or document.applets[0].buttonClicked();
            </script>
        </head>
        <body>
            <form>
                <input type="button" onclick="myfunction()" value="Call function"/>
            </form>
            <applet id="myApplet" name="myApplet" code="MyApplet.class" width="300" height="200"></applet>
        </body>
    </html>

  • Passing table parameter from dynpro for java to sap r/3

    I am sending table parameter from WebDynpro to sap r/3,but the table is not populating.

    Hi,
    In 7.3:
    // models
                RFCModel1 modeloGral = new RFCModel1();
                Zfmfi_Certificado_Ret_Pdf_Input modeloRfc =                          wdContext.currentZfmfi_Certificado_Ret_Pdf_InputElement().modelObject();
                // clean
                if(modeloRfc.getIt_Tipo_Ret_Pobl()!=null && modeloRfc.getIt_Tipo_Ret_Pobl().size()>0){
                               modeloRfc.getIt_Tipo_Ret_Pobl().removeAll(modeloRfc.getIt_Tipo_Ret_Pobl());
                //fill
                IEt_RetencionesElement retElem;
                int cant = wdContext.nodeEt_Retenciones().size();
                for(int i=0; i<cant; i++){
                   retElem = wdContext.nodeEt_Retenciones().getEt_RetencionesElementAt(i);
                   Zfie_Tipo_Retencion_Poblacion retencion = new                                                                            Zfie_Tipo_Retencion_Poblacion(modeloGral);
                                    retencion.setTipo_Ret(retElem.getTipo_Ret());
                                    modeloRfc.addIt_Tipo_Ret_Pobl(retencion);

Maybe you are looking for