Hi:) I want to display data on "input" when select "select option". I included jsp page, which have "input" tag, so using ajax send data to included jsp page.
Here's my code. Name is "new_order.jsp"
<script>
$('select#product').change(function() {
var param = "code=" + $('#product').val();
$.ajax({
url : 'add_products/add_products.jsp',
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
data : param,
type : 'POST',
dataType : 'html',
success : function(data, textStatus, jqXHR){
}
});
});
...
</script>
<body>
<table class="add_products_tb table" data-toggle="table">
<tr>
..
</tr>
<tr>
..
</tr>
<tr>
<td>
..
</td>
<td>
<table>
<tr>
<td>
<select name="product" id="product" class="selectpicker" data-width="150px">
<option data-hidden="true">-Select-
<%
try {
query = "select * from new_product";
rs = stmt.executeQuery(query);
while (rs.next()) {
product_code = rs.getString("product_code");
%>
<option value="<%= product_code %>"> <%= product_code %>
<%
}
} catch (SQLException e) {
out.println(e);
} finally {
}
%>
</select>
</td>
</tr>
</table>
</td>
<jsp:include page="add_products/add_products.jsp" />
</tr>
</table>
</body>
The Next Code. This is included jsp, "add_product.jsp"
<script>
$(document).ready(function() {
$('select#product').change(function() {
<%
product_code = request.getParameter("code");
int size = 0;
try {
query = "select * from new_product where product_code='"+product_code+"'";
rs = stmt.executeQuery(query);
while (rs.next()) {
size = rs.getInt("sizes");
%>
$('#size').val("<%= size %>");
<%
}
} catch (SQLException e) {
out.println(e);
} finally {
}
%>
});
});
</script>
...
<body>
<td>
<input type="text" id="size" class="form-control" name="size" />
</td>
<td>
<input type="text" id="color" class="form-control" name="color" />
</td>
<td>
<input type="text" id="price" class="form-control" name="price" value="0" readonly />
</td>
<td>
<input type="text" id="quantity" class="form-control" name="quantity" value="1" />
</td>
<td>
<input type="text" id="total_price" class="form-control" name="total" value="0" readonly />
</td>
</body>
The Problem is, I want to receive the data, "code", from "new_order.jsp" and display the data on "add_product.jsp", but it doesn't display on the page. I also have debugging the page, the data is sent to "add_product.jsp", but didn't display on input.
I changed a variable "product_code", placed on "add_product.jsp" script, to value, not jsp variable but special value in DB. So, there is data on "input"! Just One....
I want to display using jsp variable. Please help me...T.T Thanks.