hi !

Anyone can tell me how can i get the value of dynamic textbox on jsp page.
If i'll use
request.getParameter("elementName");
here as text box will be generated dynamically i can't assign name of the text box .
Pleeeeeeeeeeeeeeeeeeeeeeez help !!!
Thanks :)

Your question doesn't make any sense. Post an example, read about javascript

-----------------------------------------code -----------------------------

<%
 try{
   if(session!=null){
    %>

<%@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">
<%@page  import="java.sql.*,com.etravel.*,java.util.ArrayList" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Online Booking</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <form name="frmPassengerInfo" action="passengerInfo.jsp">


    <%

      // String selectedSeats = request.getParameter("hdnSelectedSeats");
      String strSelectedBoardingPoint = request.getParameter("listBP");
      String strSelectedDropingPoint = request.getParameter("listDP");
      //session.setAttribute(selectedSeats, selectedSeats);
      session.setAttribute("boardingPoint",strSelectedBoardingPoint);
      session.setAttribute("dropingPoint" , strSelectedDropingPoint);

      Object obj1=(session.getAttribute("source"));
        Object obj2=(session.getAttribute("destination"));
       Object obj3=(session.getAttribute("person"));
      Object obj4=(session.getAttribute("doj"));
       Object obj5=(session.getAttribute("trip"));
      Object obj6=(session.getAttribute("busType"));
      Object obj7=(session.getAttribute("startTime"));
      Object obj8=(session.getAttribute("reachTime"));
      Object obj9=(session.getAttribute("seatFare"));
       //Object obj10=(session.getAttribute("sleeperFare"));
       Object obj11=(session.getAttribute("totalFare"));
      Object obj12 = (session.getAttribute("selectedSeats"));

      String sessionSource=obj1.toString();
      String sessionDestination=obj2.toString();
      String sessionPerson=obj3.toString();
      String sessionDoj=obj4.toString();
      String sessionTrip=obj5.toString();
     String sessionBusType=obj6.toString();
      String sessionStartTime=obj7.toString();
       String sessionReachTime=obj8.toString();
      String sessionSeatFare=obj9.toString();
     // String sessionSleeperFare=obj10.toString();
      String sessionTotalfare = obj11.toString();
      //double sessionTotalfare = Double.parseDouble(str1);
     String sessionSelectedSeats = obj12.toString();
      int forTable = Integer.parseInt(sessionPerson);

        %>

      <%! Connection con = null;
        Statement stmtSelectBP;
        ResultSet rsSelectBP;
        Statement stmtSelectDP;
        ResultSet rsSelectDP;
        ArrayList listSelectedSeats = new ArrayList();
       %>

   <%
        String sqlSelectBP="select BoardingPoints from BoardingPoints where CityName=='"+sessionSource+"'";


        String sqlSelectDP="select BoardingPoints from BoardingPoints where CityName=='"+sessionDestination+"'";

    %>
    
<jsp:include page="header.jsp" />
<div id="round_top" ></div>
<div id="contentTop" class="fixed">
    <%
       // String selectedBus = request.getParameter("rdSelectedBus");
      
          con = (Connection) com.etravel.ConnectionClass.connection();
    %>

    <table align="center">
        <tr><td align="center"><img src="images/bus_icon.gif" alt=".." width="40" height="40" style="opacity:0.4;filter:alpha(opacity-40)" /></td>
            <td align="center"><img src="images/seat_icon.gif" alt=".." width="40" height="40" style="opacity:0.4;filter:alpha(opacity-40)" /></td>
            <td align="center"><img src="images/passenger.jpeg" alt=".." width="40" height="40"   /></td>
            <td align="center"><img src="images/tick.jpeg" alt=".." width="40" height="40"  style="opacity:0.4;filter:alpha(opacity-40)"/></td></tr>
        <tr>
           <td align="center" style="opacity:0.4;filter:alpha(opacity-40)" >Select Bus</td>
            <td align="center" style="opacity:0.4;filter:alpha(opacity-40)" >Seat Selection</td>
            <td align="center" >Passenger Info</td>
            <td align="center" style="opacity:0.4;filter:alpha(opacity-40)" >Confirmation</td>
        </tr>
    </table>
    
           <% String selectedSeat[] = sessionSelectedSeats.split(",");

           %>
    <strong><center>  <%=sessionSource%> To <%=sessionDestination%> Journy Date : <%=sessionDoj%></center></strong>
    <h5>Please fill-up the following details for ticket booking------</h5>
  
</div>

    <div id="content" class="fixed">
        <div id="maincontent">

            <table>
                <tr><th> Onward Seat(s)</th>
                    <%
                    if(sessionTrip.equals("round")){
                    %>
                <th> Return Seat(s)</th>
                <%}%>
                <th> Name of Passenger(s)</th>
                <th> Gender</th>
                <th> Age(yrs)</th></tr>
       <%
               for(int i=0;i<forTable;i++){
                  // listSelectedSeats.add(selectedSeat[i]);
                   
            %>
                <tr><td><input type="text" size="15" name="txtOnwardSelectedSeats<%=i%>" value="<%=selectedSeat[i]%>" readonly /></td>
                    <%
                    if(sessionTrip.equals("round")){

                    %>
                    <td><input type="text" size="15"  name="txtReturnSelectedSeats" readonly/></td>
                    <%}
                   %>
                    
                    <td><input type="text" name="" /></td>

                  <td> <select name="gender">
                          <option>--Select--</option>
                    <option>Female</option>
                    <option>Male</option>
                </select></td>
                <td><input type="text" size="5" /></td></tr>
               
<%}%>


            </table>
            <%
           // session.setAttribute("selectedSeats",listSelectedSeats);
            %>
            
            <table align="center">
             
                   <tr><td>Address</td><td><input type="text" name="txtAddress" id="txtAddress"  size="30"/></td></tr>
                   <tr><td>Contact Number</td><td><input type="text" name="txtNumber" id="txtNumber" size="30"/></td></tr>
                   <tr><td>Email Id</td><td><input type="text" name="txtEmail" id="txtEmail" size="30"/></td></tr>
                   <tr><td>Id Card Type</td><td><select>
                               <option>----Select----</option>
                               <option>Driving License</option>
                               <option>Passport Number</option>
                               <option>PAN Card </option>
                                <option>Voter ID</option>
                               <option>Central/State Govt. issued ID</option>
                               <option>Others</option>
                           </select></td></tr>
                   <tr> <td>If Others</td><td><input type="text" name="txtOthers" id="txtOthers" size="30" /></td></tr>
                   <tr><td>Id Card Number</td><td><input type="text" name="txtIdCardNumber" id="txtIdCardNumber" size="30"/></td></tr>
                   <tr><td>Issuing Authority</td><td><input type="text" name="txtIssuingAuthority" id="txtIssuingAuthority" size="30" /></td></tr>
               </table>
            <center>  <font color="red" size="1"> <b>ID card details are mandatory for ticket cancellation.<br>
                Please provide ID Card Type, ID Card Number and Issuing Authority. <br>
                These are necessary to cancel the ticket.</b></font></center>

        </div>
        <div id="sidebar">

            <table>
                <tr>
                    <th colspan="100%">
                        Travel Details
                    </th>
                </tr>
                <tr></tr><tr></tr><tr></tr><tr></tr><tr><tr></tr><tr></tr>
                <tr><td>Bus Type</td><td>:<%=sessionBusType%></td></tr>
                <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>Source</td><td>:<%=sessionSource%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>Destination</td><td>:<%=sessionDestination%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
               <tr><td>Start Time</td><td>:<%=sessionStartTime%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>Reach Time</td><td>:<%=sessionReachTime%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                 <tr><td>Boarding Point</td><td>:<%=strSelectedBoardingPoint%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>Droping Point</td><td>:<%=strSelectedDropingPoint%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>Number Of Persons</td><td>:<%=sessionPerson%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
               <%-- <tr><td>Selected Seats</td><td></td><td>:<%=selectedSeats%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>--%>
                <tr><td>Seat fare</td><td>:<%=sessionSeatFare%></td></tr>
                 <tr></tr><tr></tr><tr></tr><tr></tr>
                <tr><td>total Fare</td><td>:<%=sessionTotalfare%></td></tr>
                
            </table><br><br><br><br><br><br>

               <a href="seatBooking.jsp"><img src="images/back.jpg" height="25" width="80" alt="Back" border="0" /></a>
                <input type="image" src="images/continue.jpg" height="25" width="80" alt="Continue" border="0"/>
        </div>
               
              </div>
<div id="round_bottom" ></div>
          <jsp:include page="footer.jsp" />
    </form>
</body>
</html>
<%
  }
 }
 catch(Exception e){
     out.println("exception" +e);
     %>
    <%-- <script language="javascript">var answer = confirm("Session expired! Want to go to the home page?")
	if (answer){

                  window.location="index.jsp"

              }
	else{

             window.close();
                 }</script>--%>
    <% } %>

how will i get value from the textboxes given for name,gender,age as textbox increases according to number of seats selected.

I am not going to read that! And it is clear that you don't know how to write proper HTML as well. Try to learn first HTML and post some code that can read. Use the button (code) when creating a new post.

And this:

<tr></tr><tr></tr><tr></tr><tr></tr>

Is not proper html

headache on this thread ....

@nikita.chandra what on Earth you trying to do copying whole Daniweb page content and reposting it?

i understand your code.. actually i'm new to web development and this is the most idiotic method of writing the front end code..i experienced a similar problem as what ever data i will send to the dynamically created boxes will be replaced to "null" at the end of try block. basically assigned with values and then flushed... logically it's a good code but.. fuctionally it isn't. most of the programmers use dynamic creation of rows in almost all examples in a seperate fuction in <script>..</script> THE ERROR IN YOUR CODE CAN BE RESOLVED BY CLOSING <input> tag with </input>.. MOST OF THEM IGNORE CLOSING IT AS IT SERVES THE FUNCTIONALITY.. BUT WHEN IT IS CONSERNED WITH DATA SENDING TO A SERVLET;WE MUST CLOSE IT ELSE IT WOULD SEND NULL VALUES.. this is an old post.. yet i want to give a reply because many are out there who think differently like this..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.