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

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









Related Tutorials/Questions & Answers:
How to automatically change the value of the textbox based on the dropdown list?
dropdown vlaue changes based on input given in textbox uisng AJAX
Advertisements
How to change the dropdown values based on other dropdown in itext pdf or in any other?
Dependant Dropdown Lists
how to display textbox value based on selected option value?
creating dropdown lists in jsp
how to set value of dropdown list
how to set value of dropdown list
Javascript change textbox background
how to load value in dropdown list after selecting value from first dropdown list using javascript
How to change the checkbox value dynamically.
binding data with textbox on dropdown click
change navbar dropdown color in bootstrap
How to create textbox on combo value selection using javacsript in jsp?
JavaScript change background color automatically
change value of mutable string
how to use dropdown list in JSP and display value in same page
How to change focus among multiple select boxes?
ModuleNotFoundError: No module named 'listx'
how to set a value of dynamic number of drop down lists on a jsp page and access it value on another jsp page
ModuleNotFoundError: No module named 'listy'
. Display JavaScript dropdown selected value
store dynamic generated textbox value into database
change uislider value
For every option selected from a dropdown a new textbox opens
How to change value of div using Ajax in struts.
change value - Ajax
lists
dropdown
how to check the radio button automatically depending up on the value of database when editing the form...
get value from multiple textbox in jsp
populating textbox value from the database using onchange function,
How automatically calculate age based on date of birth and current date using jsp and servlet?
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
ModuleNotFoundError: No module named 'listy-django-cache'
ModuleNotFoundError: No module named 'list1'
ModuleNotFoundError: No module named 'list1'
help to select a value from the dropdown list
change color according to the database value
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 ???
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
ModuleNotFoundError: No module named 'lista'
Selecting value from autocomplete textbox using jquery in jsp
to access value of drop down value in beans when dropdown is populated using ajax
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.
populating one dropdown box depending on the value of other using jsp
Retriving value from dropdown list nad disply it in other page
How to change background, change background

Ads