0

i have code like this
in page1.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">

    <body>
        <h1>Test</h1>

        <script language="javascript">
            function JSGetSelectedItem() {
                var dropdownIndex = document.getElementById('lang').selectedIndex;
                var dropdownValue = document.getElementById('lang')[dropdownIndex].text;
                alert("Hello JSCript " + dropdownValue);
            }

        </script>

        <!-- to fill combobox i had get from database -->   

        <form method="post" action="page1.jsp"> >
            Please select
            <select name="lang" onChange="JSGetSelectedItem()">
                <c:forEach var="v_Init" items="${ma_Init}">
                    <option value="scem">${v_Init.schem}</option>
                </c:forEach>
            </select>
        </form>

        <a href="page2.jsp?lang="<%=request.getParameter("lang")%> >Your Select</a>

    </body>
</html>

in page2.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Page 2</title>
    </head>
    <body>

     <%
      String selectedValue=request.getParameter("lang");
      out.println("Selected Value is : "+selectedValue);
     %>

    </body>
</html>

thanks

Edited by diafol: fixed formatting

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by anand01
0

try it this way

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">

    <body>
        <h1>Test</h1>

        <script language="javascript">
            function JSGetSelectedItem() {
                var dropdownIndex = document.getElementById('lang').selectedIndex;
                var dropdownValue = document.getElementById('lang')[dropdownIndex].text;
                alert("Hello JSCript " + dropdownValue);
            }
 
        </script>
  
        <!-- to fill combobox i had get from database -->   

        <form method="post" action="page2.jsp"> >
            Please select
            <select name="lang" onChange="JSGetSelectedItem()">
                <c:forEach var="v_Init" items="${ma_Init}">
                    <option value="scem">${v_Init.schem}</option>
                </c:forEach>
            </select>
           <input type = "button" value = "submit" id = "submit"/>
        </form>
    </body>
</html>

just change the form action to paje2.jsp. then add a button. i usually do the same and it works.

Edited by Mindpowerh: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.