我想在文本框中显示下拉列表中所选项目的数量

时间:2022-02-11 07:42:24
<script type="text/javascript">

function showconfirm() {
    var a = confirm("Do you want to Buy ?");    
    if(a == true) {
        alert("Book is Yours!");
    } else {
        alert("Paisa nahi hai toh aage bado!!");
    }
}
</script>

my problem is the price and quantity of last item in the database is getting populated into the textbox. This shouldn't be the case. Quantity and price should change everytime I select a new item.

我的问题是数据库中最后一项的价格和数量是否已填入文本框。情况并非如此。每次选择新项目时,数量和价格都应该改变。

<table align = 'center' cellspacing='15' style = "background-color:brown" >
    <tr>    

      <%
       try {
          data = new MysqlDataSource();
          con =  data.getConnection("root","system");
          System.out.println("Connected to MySQL"); 
          PreparedStatement pre = con.prepareStatement("select * from library.booklist");
          result = pre.executeQuery();       
      %> 

        <td> <i> Book List : </i></td> 
         <td> <select name= "BookList" id="Booklist" > 
              <option> - select - </option>
    <%  
    while (result.next())  
    {
           name = result.getString("Book"); 

    %>
    <option value="<%=name%>"> <%=name%></option>

    <% 
    }
}
catch (SQLException e1) {
    e1.printStackTrace();
}
    %>
</select>
</td>
</tr>

    <tr>
       <%
    try {
     ItemNames [] = request.getParameterValues("BookList");
     System.out.println(ItemNames);
     pre = con.prepareStatement("select Quantity from library.booklist where Book = ? ");  
     pre.setString(1,ItemNames); 
      result = pre.executeQuery();
      %>
     <td><i> Quantity : </i>  </td>
  <%
    while (result.next())  
    {
       int show = result.getInt("Quantity"); 
  %>
<td> <input name = "Quantity" id = "Quantity" type = "text" size = "10" readonly = "readonly" value = "<%=show%>"> </td>
   <%
   }
   } 
    catch (SQLException e1) 
    {
    e1.printStackTrace();
    }

   %>
   </tr>



     <tr> 
    <%
    try {
     pre = con.prepareStatement("select Price from library.booklist where Book = ? ");  
     pre.setString(1,name); 
      result = pre.executeQuery();
      %>

      <td><i> Price : </i>  </td> 
   <%
    while (result.next())  
    {
       double mrp = result.getDouble("Price"); 
   %>

<td> <input name = "Price" id = "Price" type = "text" size = "10" readonly = "readonly" value = "<%=mrp%>">  </td>
   <%
   }
   } 
    catch (SQLException e1) 
    {
    e1.printStackTrace();
    }  
   %>
     </tr> 

    <tr>
    <td> </td>
    <td><input label='Submit' value='Buy' type='Submit'  onclick = 'showconfirm()' value ='Showconfirmbox' /> </td>
    </tr>
</table>   

I want to display price and quantity into a textbox on selecting any item from drop down list. The data is stored in Database. How to get selected data from list in jsp?

我想在下拉列表中选择任何项目时将价格和数量显示在文本框中。数据存储在数据库中。如何从jsp列表中选择数据?

1 个解决方案

#1


0  

Quantity and price should change everytime I select a new item.

每次选择新项目时,数量和价格都应该改变。

Javascript and Ajax. If you want something to happen when the user does something on the interface, you have to use Javascript. Because only Javascript can respond to client-side events.

Javascript和Ajax。如果您希望在用户在界面上执行某些操作时发生某些事情,则必须使用Javascript。因为只有Javascript才能响应客户端事件。

How to get selected data from list in jsp?

如何从jsp列表中选择数据?

In this code you are building the page to send to the client. Obviously since the client has not seen the page yet, they haven't selected anything.

在此代码中,您将构建要发送给客户端的页面。显然,由于客户端尚未看到该页面,因此他们没有选择任何内容。

#1


0  

Quantity and price should change everytime I select a new item.

每次选择新项目时,数量和价格都应该改变。

Javascript and Ajax. If you want something to happen when the user does something on the interface, you have to use Javascript. Because only Javascript can respond to client-side events.

Javascript和Ajax。如果您希望在用户在界面上执行某些操作时发生某些事情,则必须使用Javascript。因为只有Javascript才能响应客户端事件。

How to get selected data from list in jsp?

如何从jsp列表中选择数据?

In this code you are building the page to send to the client. Obviously since the client has not seen the page yet, they haven't selected anything.

在此代码中,您将构建要发送给客户端的页面。显然,由于客户端尚未看到该页面,因此他们没有选择任何内容。