How to automatically change the value of the textbox based on the dropdown list?

Ads
 

How to automatically change the value of the textbox based on the dropdown list?

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>
View Answers

Ads









Related Tutorials/Questions & Answers:
How to automatically change the value of the textbox based on the dropdown list?
how to display textbox value based on selected option value?
Advertisements
How to change the dropdown values based on other dropdown in itext pdf or in any other?
dropdown vlaue changes based on input given in textbox uisng AJAX
Dependant Dropdown Lists
How to change the checkbox value dynamically.
How automatically calculate age based on date of birth and current date using jsp and servlet?
how to load value in dropdown list after selecting value from first dropdown list using javascript
creating dropdown lists in jsp
How to create textbox on combo value selection using javacsript in jsp?
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
change navbar dropdown color in bootstrap
how to use dropdown list in JSP and display value in same page
binding data with textbox on dropdown click
How to change focus among multiple select boxes?
change value of mutable string
how to set a value of dynamic number of drop down lists on a jsp page and access it value on another jsp page
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
How to change value of div using Ajax in struts.
store dynamic generated textbox value into database
how to check the radio button automatically depending up on the value of database when editing the form...
. Display JavaScript dropdown selected value
change uislider value
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
For every option selected from a dropdown a new textbox opens
get value from multiple textbox in jsp
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
populating textbox value from the database using onchange function,
ModuleNotFoundError: No module named 'listx'
dropdown

Ads