How to call Java code from Javascript and assign a value to a JSP page?
Posted
by
Frank
on Stack Overflow
See other posts from Stack Overflow
or by Frank
Published on 2012-09-24T15:35:54Z
Indexed on
2012/09/24
15:37 UTC
Read the original article
Hit count: 201
I have the following "form.jsp" program, it generates a drop down list, below the list is a textarea to show the display_name of a selected item, now when user selected a item, it shows the selected item id in the textarea, how to call the DB from my code and get the display_name in the javascript so the result display_name will be shown in the textarea ?
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
function callme(Display_Name)
{
alert('callme : Display_Name = '+Display_Name);
var v=document.getElementById('hiddenValue').value;
alert('hiddenValue : v = '+v);
document.getElementById('defaultDisplayName').value=Display_Name;
}
</script>
<s:hidden id="pricelist.id" name="pricelist.id" value="%{pricelist.id}"/>
<div class="dialog">
<table>
<tbody>
<s:if test="%{enableProductList}">
<tr class="prop">
<td valign="top" class="name required"><label for="description">Product:</label></td>
<td valign="top">
<s:select id="productPrice.product"
name="productPrice.product"
headerKey="0"
headerValue="-- Select Product --"
list="products"
listKey="id"
listValue="name"
value="productPrice.product.id"
theme="simple"
displayName1='value'
onchange="callme(value)"
/>
<s:hidden id="hiddenValue" name="hiddenValue" value="123"/>
</td>
</tr>
</s:if>
<tr class="prop">
<td valign="top" class="name"><label for="description">Default Display Name:</label></td>
<td valign="top"><s:textarea id="defaultDisplayName" name="defaultDisplayName" theme="simple" readonly="true"/></td>
</tr>
See attached image for details, in the DB, a product table has the product Id and display_name, I know the Id, how to use Java to get the display_name and plug it into the jsp ?
© Stack Overflow or respective owner