Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to calculate values dynamically from textbox using jQuery?
    primarykey
    data
    text
    <p>I have an <code>invoice.jsp</code> page where I have to calculate some value in the textbox using jQuery or with any other way.</p> <p>I don't know much about jQuery. Please help me to solve this problem.</p> <p>In my invoice there is a quantity textbox. If the user enters the quantity then the calculated price should be calculated dynamically i.e <code>(total_subPrice= unit_price * quantity)</code> and shown in another textbox called "price".</p> <p>And again the total sum of all the prices should appear in the button as a Total.</p> <p>Please note: all the row values are coming from my database table based on the selection of items by users.</p> <p>I have used only this code to show values in my <code>invoice.jsp</code> page:</p> <pre><code>&lt;s:iterator value="#session.BOK" status="userStatus"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="65%" align="left"&gt;&lt;s:property value="bookTitile"/&gt;&lt;/td&gt; &lt;td width="10%" align="left"&gt;&lt;s:property value="price"/&gt;&lt;/td&gt; &lt;td width="10%" align="center"&gt;&lt;s:textfield name="quantity" value="%{quantity}" size="2" /&gt;&lt;/td&gt; &lt;td width="15%" align="center" &gt; &lt;s:textfield value="%{price}" name="" size="6"&gt;&lt;/s:textfield&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/s:iterator&gt; </code></pre> <p>And my <code>invoice.jsp</code> output looks like this: <img src="https://i.stack.imgur.com/DQMz4.png" alt="enter image description here"></p> <p>I have no idea how to calculate the <code>line Total</code> based on the quantity chosen and also display the sum of all the <code>line total</code> in the grand total textbox (see below invoice image).</p> <p>I also tried <a href="http://jsfiddle.net/bozdoz/LGyeq/" rel="nofollow noreferrer">this</a> but I am still unable to solve my problem.</p> <p>My full JSP code:</p> <pre><code>&lt;table width="100%" height="50%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt; &lt;td height="74%"&gt; &lt;s:form action="dfs" id="form3" theme="simple"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="your_content"&gt; &lt;tr&gt; &lt;td valign="top" height="10%"&gt; &lt;div id="invNum"&gt;Invoice# 12688&lt;/div&gt; &lt;div id="ttielMain"&gt;Vision Books&lt;/div&gt; &lt;div id="Orgaddress"&gt; Thamel Kathmandu Nepal&lt;/div&gt; &lt;div id="phoneNum"&gt; Tel# 00977-1-12173803&lt;/div&gt; &lt;div id="websiteOrg"&gt; www.thebestbookfinder.com&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="100%" align="left"&gt; ----------------------------------------------------------- ----------------------------------- &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="6%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;font-family: serif;font-weight: bold;font-size: 14px;"&gt; &lt;td width="65%" align="left"&gt;Title&lt;/td&gt; &lt;td width="10%" align="left"&gt;Unit Price&lt;/td&gt; &lt;td width="10%" align="center"&gt;Qty&lt;/td&gt; &lt;td width="15%" align="left"&gt;Line Total&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="65%" align="left"&gt; ------------------------------------------------------- &lt;/td&gt; &lt;td width="10%" align="left"&gt;----------&lt;/td&gt; &lt;td width="10%" align="center"&gt;-----&lt;/td&gt; &lt;td width="15%" align="left"&gt;-------------&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="65%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;s:iterator value="#session.BOK" status="userStatus"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="65%" align="left"&gt;&lt;s:property value="bookTitile"/&gt;&lt;/td&gt; &lt;td width="10%" align="left"&gt;&lt;s:property value="price"/&gt;&lt;/td&gt; &lt;td width="10%" align="center"&gt;&lt;s:textfield name="quantity" value="%{quantity}" size="2" /&gt;&lt;/td&gt; &lt;td width="15%" align="center"&gt;&lt;s:textfield value="%{price}" name="" size="6"&gt;&lt;/s:textfield&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/s:iterator&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5"&gt; ------------------------------------ &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5" style="font-weight: b"&gt; &lt;s:set var="total" value="%{0}" /&gt; &lt;s:iterator value="#session.BOK"&gt; &lt;s:set var="total" value="%{price + #attr.total}" /&gt; &lt;/s:iterator&gt; &lt;s:textfield name="subtotal" value="%{'' + #attr.total}" size="5"&gt; &lt;/s:textfield&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5"&gt;Discount:&lt;sj:textfield name="amt" size="1" placeholder=" %"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5"&gt; -------------------------------------------------------------------------------------------------- &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5" style="font-weight: bolder;"&gt; &lt;s:set var="total" value="%{0}" /&gt; &lt;s:iterator value="#session.BOK"&gt; &lt;s:set var="total" value="%{price + #attr.total}" /&gt; &lt;/s:iterator&gt; Total: &lt;s:property value="%{'' + #attr.total}" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="1%" valign="top" width="100%"&gt; &lt;table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr style="height: 10px;"&gt; &lt;td width="100%" align="right" colspan="5"&gt; -------------------------------------------------------------------------------------------------- &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload