How to assign java script variable to a hidden parameter in JSP?

Hi All,
I want to assign the variable in the Jscript to a hidden parameter in JSP page.
<select name="sortingOption" class="sortingOptions" onchange="changeSortOption(this)">
<c:forEach var="sortingOption" items="${sortingOptionList}">
<c:set var="sortingOptionValue" value="${sortingOption}" target="java.lang.String"/>
<c:choose>
<c:when test="${sortingOptionValue == sortingOptionValueFromRequest}">
<option value="${sortingOptionValue}" selected="selected">${sortingOptionValue}</option>
<input type="hidden" name="srchType" value="none"/>
</c:when>
<c:otherwise>
<option value="${sortingOptionValue}">${sortingOptionValue}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
In changeSortOption script,they capture the value selected by the user and then they submit the form.I want to assign that value to a hidden parameter in JSP,can someone tell me how to do that?
I dont have the Jscript code with me right now to post here.

To the point: just by accessing/manipulating the HTML DOM using JS. Learn JS and HTML DOM. There are basic tutorials at w3schools.com. Besides, your code syntax is still invalid. The input hidden elemend doesn't belong in a select element. Learn HTML. There's a basic tutorial at w3schools.com as well.
For future HTML/JS problems please consult the appropriate forums. This has not much to do with JSP. There are ones at webdeveloper.com.

Similar Messages

  • Use a Java Script variable's value in some other  jsp ....how?

    Please help me.................
    <%@ page import="java.util.*" %>
    <%@ page language = "java" import="java.sql.*,javax.servlet.*,javax.servlet.http.*,java.util.*" session = "true" %>
    <HTML>
    <HEAD>
    <TITLE>Create Employee</TITLE>
    </HEAD>
    <BODY>
    <%
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         try {
              Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://10.203.143.55:3306/bdaymgr" ,"root","mysql");
              stmt = conn.createStatement();
              rs = stmt.executeQuery("Select emp_id,emp_name From employee_info ");
              System.out.println("rs " + rs);
    %>
    <script language="JavaScript">
         function OnSubmitForm(){
         var box = document.form2.UserList;
         var where_to = box.options[box.options.selectedIndex].value;
         if(where_to =="")
    {document.write("Please select something");}
         else {Dont know what to do here }
         </script>
    </script>
    <center>
    <FORM NAME = "form2" onSubmit="OnSubmitForm();">
    <table>
    <TR>
         <TD width="11%">User ID : </TD>
         <TD width="180%"><select name="UserList" size="1">
         <option>-- Select A User ID --<option>
         <% while (rs.next()) {
         %>
         <option value='<%= rs.getString("EMP_ID")%>' ><%=rs.getString("EMP_ID") %></option>
         <% } %>
         </select>
         <input type="hidden" name="score" value="">
         <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
         </TD></TR>
    </TABLE>
    </FORM>
    </Center>
    <%
              stmt.close();
                   rs.close();
              catch(Exception e){
                   System.out.println("Error : "+ e);
                   response.sendRedirect("errorcreateSession.jsp");
    %>
    </BODY>
    </HTML>
    As u can see i have extracted emp_id from the employee_info table and populated it in my drop down list
    In the javascript i have used a variable "where_to" which keeps track of what the user has selected in the drop down list
    I want to use this value of "where_to" in some other other jsp(say Admin.jsp) to carry out an insert query
    how can i retrieve this value of "where_to" from Admin.jsp so that i can carry out my insert query
    Thanx in advance i certainly hope that u will help me

    I made these changes in my Guest.jsp page(as u mentioned):
    <FORM NAME = "form2" onSubmit="return OnSubmitForm();" action="Admin.jsp">
    <select name="UserList" size="1">
         <option>-- Select A User ID --<option>
    </select>
         <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
    <script language="JavaScript">
         function OnSubmitForm(){
         var box = document.form2.UserList;
         var where_to = box.options[box.options.selectedIndex].value;
         if(where_to =="")
    document.write("Please select something");
    return false;
    else
    return true;
    </script>
    Now have a look at my Admin.jsp page:
    <%@ page import="java.util.*" %>
    <%@ page language = "java" import="java.sql.*,javax.servlet.*,javax.servlet.http.*,java.util.*" session = "true" %>
    <HTML>
    <HEAD>
    <TITLE>Create Employee</TITLE>
    </HEAD>
    <BODY>
    <%
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         PreparedStatement ps = null;
         try {
              Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://10.203.143.55:3306/bdaymgr" ,"root","mysql");
              String s=request.getParameter("UserList");
              String m=request.getParameter("month");
              String y=request.getParameter("year");
              String a=request.getParameter("amount");
              String sql="insert into contribution_info values(?,?,?,?)";
              ps=conn.prepareStatement(sql);
              ps.setString(1,s);
              ps.setString(2,m);
              ps.setString(3,y);
              ps.setString(4,a);
              ps.executeUpdate();
              System.out.print("Values Entered");
              %>
    <center>
    <FORM NAME = "form3" action="canBeAnyPage.jsp">
    Month :<br><input type=\"text\" name="month"><br>
    Year :<br><input type=\"text\" name="year"><br>
    Amount Paid :<br><input type=\"text\" name="amount"><br>
    <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
    </FORM>
    </center>
    <% stmt.close();
                   rs.close();
              catch(SQLException e){
                   System.out.println("Error : "+ e);
                   //response.sendRedirect("errorcreateSession.jsp");
    %>
    </BODY>
    </HTML>
    I dont know why but when i select one of the emp_id from the drop down list and press submit it does not show anything
    I can see the value of "UserList" in the url which is correct
    Probably there is some problem in my Admin.jsp page
    Please find time to have a look at my code
    Help would be really appreciated
    thanx

  • Assigning java script array to java array..

    hi,
    can anyone tell me how to assign java script array to a java array which is bean.

    var input = document.createElement("input");
    input.setAttribute("type", "hidden");
    input.setAttribute("name", "bla..bla");
    input.setAttribute("value", "bla..bla");And in addition to that.. Google is still alive

  • How to access a JAVA Script variable in JSP Code

    How to access a JAVA Script variable in JSP Code. I have been unable todo this.
    Plz Suggest a way.
    Thanks
    Soumya

    try to do this code
    String s=request.getParameter("javascriptvariablename");

  • How to pass a java script variable to a JSP page

    How to assign a javascript variable value to a jsp variabe
    <script>
    var scroll="100"
    </script>
    <%
    String age=[ here i need to set the value of "scroll" ]
    %>
    is it possible ,
    thanks

    assign this scroll to a hidden field in a form
    and pass via form to server this may be one way or
    set attribute scroll and then access to server side
    may this help you
    --yogeshb                                                                                                                                                                                                                                                                                                                                                                           

  • Returning/passing Java script variable/value to PL/SQL environment

    Hi,
    Can someone give me a sample code about how to return a Java script variable to PLSQL environment?
    for example, I have a javascript function that returns timestamp in milisecond, I then want to write PLSQL code to call this java script function and save its value in a number-typed plsql variable for further calculation, I dont know how the two scripting language communicate.
    Thank you very much
    Binh
    null

    This is quite simple.
    I assume that you are able to define html form side through pl/sql. Suppose your new pl/sql value is v_time then in the procedure that you write include one more statement
    htp.p('<Input type=hidden name="v_time" value="">');
    and also in the form invocation,
    htp.p('<form name=app method=post action="time_handler" onSubmit="return false;">');
    and to the end you must be having a submit
    to it attach a onClick function that calls
    simply our validate function..
    eg htp.p('<Input type=submit value="process"
    onClick="validate();">');
    Include in the head portion
    the following script using htp.p procedure
    function validate()
    app.v_time.value=<calculated value>;
    return app.submit();
    Hope this helps.
    Nat
    null

  • Passing importing parameter in  ABAP to  java script variable

    Hi Experts,
    I am calling a ABAP function module in javascript.Now how can I take importing parameter in  ABAP to java script variable. Because I need to give alert using the improting Paramter value...
    Thanks in advance..
    RR

    to pass ABAP variable value to javascript variable the syntax is
    var myjsvariable = "<%=abapvariable%>";
    Edited by: Durairaj Athavan Raja on Jul 29, 2009 2:39 PM

  • How to Include JAVA script code in SAP BI7 web Reporting?

    How to Include JAVA script code in SAP BI7 web Reporting?

    In nw2004s there is a new web item called "Script" web item which lets you add javascript code. When you add javascript code in this web item, you don't need the opening and closing <script> tags...
    Hope it Helps
    Chetan
    @CP..

  • How to call java script function from JSP ?

    how to call java script function from JSP ?

    i have function created by java script lets say x and i want to call this function from jsp scriplet tag which is at the same page ..thanks

  • How to enable java script in my Firefox browser? help its urgent.

    how to enable java script in my Firefox browser? help its urgent.

    go to '''about:config''' and search for '''javascript.enabled''' change its value to '''true'''
    *[http://kb.mozillazine.org/About:config about:config]

  • How to enable java script in firefox

    how to enable java script in firefox

    See:
    *[[JavaScript]]
    Also make sure that an extension isn't causing problems.
    * [[Troubleshooting extensions and themes]]

  • How to build JAVA script in CMD

    How to build JAVA script in CMD command prompt?
    I think it's build.all but it's not working plz help

    To build a Java class file (ie compile it) you need to call the Java compiler javac. There is software around to make this easier:
    - ANT a make like tool but with XML files usually called build.xml
    - Maven a more convention driven approach for much complexer systems
    - IDEs like JDeveloper, Netbeans, Eclipse, you name it.
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use java script when popups are blocked in browser

    How to use java script when popups are blocked in browser

    Not. When people install a popup blocker they don't WANT popups, so stop trying to force them down their throats.

  • How to write Java Scripts in Apex

    Hi All,
    Can any on tell me how to write Java Scripts in Apex.
    Thanks in Advance,
    Mukund

    If you want to link your custom JavaScripts to an Apex page, you have several options:
    1. Add an HTML Region on Page 0 (Script will be written to every page) called something like "JavaScript & CSS". In this region add your Script to the region source like this:
    <script language="JavaScript">
    function hell ()
    alert ("Hello World");
    </script>
    2. Add a similar region to the page you are working on (can only be accessed on this page)
    3. Create an external JavaScript file and either load it into the WORKSPACE or into the images (/i/) directory on the server. You can then link the JS into you page via modifying the Page Template.
    Hope that makes sense. Let me know if you want any further help with option 3.
    Duncs

  • Assigning a jstl variable to java Script variable

    Hai All,
    I created one jsp page with java script with JSTL.
    I retrive arrayList from simple java bean in jsp page with help of JSTL .
    Now i want assign the ArrayList value through JSTL to Java Script Array.
    How to convert JSTL to Java Script.
    Please give me details asp.
    thanks ,
    Bala

    You can do this:
    <% request.setAttribute("x", "hello"); %>
    <c:out value="${x}"/>or if you want to go from JSTL to scriplet you can:
    <c:set var="testvar" value="hello" scope="request"/>
    <%= request.getAttribute("testvar") %>Both of these will output "hello"
    <c:set> defaults to the page scope, so you could substitute pageContext for request and get the same results (remove scope="request" first though).
    Karl

Maybe you are looking for

  • How to make as selection variable

    Hi All we have one variable plant. the variable is properties are: genral properties: Type of variable : Characteristic Processing by : Authorization Reference charateristic : plant. Details: Variable represents : Multiple single values variable is :

  • SCOM 2012 Network Monitoring Does Not Show Servers

    We are testing out the network monitoring piece in SCOM 2012 but for some reason it never does show the servers.  We have a test switch with a monitored server connected directly to it but after the discovery completes it doesn't show the server as b

  • Image Mask confusion

    I'm trying to create an image mask but I'm stuck. I can create the mask on an object. But when I attempt to drag an image into the well, the moment my mouse button goes down, the image is selected instead of the mask and so the inspector changes and

  • Text quality

    I am attempting to create a magazine cover with picture and text.  I have sussed out the pictures, but the text quality is rather naff on printing (depending on the font I use)  Any suggestions to how to improve the font or are there particular fonts

  • Getting Stuck on Auto Updating

    Hi I have a Newish Macbook pro 3 months old , and running Leopard 10.5.1 and when it does the Auto update , It says I need to restart the computer to finish update , when I do this it starts with the Blue timeline but never moves , I have left it on