Isaac Chua
How to automatically change the value of the textbox based on the dropdown list?
0 Answer(s)      2 years ago
Posted in : JSP-Servlet

I want to know how to automatically change the value of price and the quantity text boxes.

Here is my code:

    <%@ page import="java.sql.*" %>

<% Class.forName("com.mysql.jdbc.Driver");
String scid=(String)session.getAttribute("scid");
String s_in=request.getParameter("s_in");
session.setAttribute("s_in",s_in);
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy/MM/dd");
%>

<html>
<head>
<title>Deliver</title>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/interface.js"></script>
<link type="text/css" href="jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.datepick.js"></script>
<script type="text/javascript">
$(function() {
    $('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'});
    $('#inlineDatepicker').datepick({onSelect: showDate});
});

function showDate(date) {
    alert('The date chosen is ' + date);
}
</script>
<script language="JavaScript">
function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;

}
</script>
    <SCRIPT language=Javascript>
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       //-->
    </SCRIPT>

</head>

<body>
<br><br><br> 
 <center>

 <form method="get" action="delib.jsp" name="del" onsubmit="return confirm('Are you sure?')" >

 <table>
<tr>
                    <td>Customer's Name:</td>
                    <td><input type="text" name="cus" required="required" value="" size=20px/></td>
</tr>
<tr>
                    <td>Item Name: </td>
                    <td colspan="4">
                        <select name="purchase" onchange="document.getElementById('vid').value=this.option[this.selectedIndex].text">
                        <option>Select One</option>
                   <%
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/e_gomez","root","12345");

                        Statement stmt = con.createStatement() ;
                        stmt=con.prepareStatement("Select item_name from items order by item_name");
                        ResultSet rst2=stmt.executeQuery("Select * from items where item_stat!='Archived' order by item_name");
                        while(rst2.next())
                       {
                   %>
                            <option><%=rst2.getString("item_name")%></option>
                   <%
                        }


                   %>
                        </select>
                    </td>
</tr>
<tr>
                    <td>Quantity:</td>
                    <td><input type="text" name="quan" onkeypress="return onlyNumbers();" required="required" value="" size=20px/></td>
</tr>

<tr>
                    <td>Unit Price:</td>
                    <td><input type="text" name="price" required="required" value="" size=20px/></td>
</tr>

<tr>
                    <td style="color:red">Discount Given (in percentage):</td>
                    <td><input type="text" name="disc" required="required" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'0':this.value;" value="0" size=20px onkeypress="return onlyNumbers();"/></td>
</tr>

<tr>
                    <td style="color:red">Delivery Charge:</td>
                    <td><input type="text" name="disc" required="required" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'0':this.value;" value="0" size=20px onkeypress="return onlyNumbers();"/></td>
</tr>

<tr>
                    <td>Date of Purchase:</td>
                    <td><input type="text" name="datepicker" readonly="readonly" required="required" id="popupDatepicker" value="<%= df.format(new java.util.Date()) %>"></td>
</tr>

<tr>
                    <td>Prepared By:</td>
                    <td><input type="text" name="prep" readonly="readonly" value="<%=scid%>"></td>
</tr>
<tr>
<td><td><input type="submit" value="Add Item to Purchase"><input  type="reset"  value="Clear" /></td></td>
</tr>
</form>

</center>  

</body>
</html>
Advertisement
View Answers









Related Tutorials/Questions & Answers:
Advertisements