如何将jsp页面中显示的列表值传递给java中的javascript方法

时间:2014-04-04 06:55:19

标签: java javascript jquery html jsp

<%@ta glib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<pre>Bin</pre>
<pre>UPC Code</pre>
<pre>Total Tickets</pre>
<pre>Balance</pre>
<pre>Value</pre>
<pre>Tickets Sold</pre>
<pre>Total</pre>
<pre>End of Life</pre>

<c:forEach items="${scratchlistlotto }" var="sl">
   <input name="scratchid" type="hidden"    id="scratchid"  value="${sl.scratchid }" />             
   <input name="binid" type="text"  class="table_color1" id="binid"   value="${sl.bin }" /> 
   <input name="upccode" type="text"   id="upccode"   value="${sl.upccode }" /></td>

   <input name="totalticketss" type="text"   id="totalticketss"   value="${sl.totaltickets }"/>
   <input name="openingbalance" type="text" id="openingbalance" value="${sl.closingbalance }" />
   <input name="closingbalnce" type="text" id="closingbalnce" onchange="javascript:Total(this.value)"    />    

   <input name="value" type="text"   id="value"   size="6" value="${sl.values }" /> 
   <input name="ticketssold" type="text"   id="ticketssold"   /> 
   <input name="total" type="text"   id="total"   />
   <input type="text" name="hidden" value="${sl.i }"/>
   <input name="endoflife" type="checkbox" class="text_border" id="endoflife"    /></td>

</c:forEach>

JS

function Total(v) { 
    var closingbalnce = parse Float(v);         
    var openingbalance = document.getElementById["openingbalance"].value;        
    var ob = document.getElementById["closingbalnce"].value;

    alert("hiiii "+ob);        
    alert("closingbalnce "+openingbalance); 

    var totalscratchtotal = parseFloat(document.name.totalscratchtotal.value);        
    var ts = closingbalnce-openingbalance;         
    document.name.ticketssold.value = ts;         
    var value = parseFloat(document.name.value.value);        
    document.name.total.value = ts  *value;          
    document.name.totalscratchtotal.value = totalscratchtotal + (ts * value);
}

我通过使用jstl标签在jsp页面中显示我的列表值我的数组列表是(scratchlistlotto)我想将我的期初余额发送到java脚本方法当我把我的期末余额放在&gt;文本框中请帮助我

2 个答案:

答案 0 :(得分:0)

您可以将列表中的值传递给js方法,就像这样

<script>Total('${sl.closingbalance }')</script>

答案 1 :(得分:0)

function Total(v) 
      {   
//var closingbalnce=parseFloat(v);
var  closingbalnce=parseFloat(v);   
var hidden=parseFloat(document.name.hidden.value);    
var op="openingbalance".concat(hidden);  
var ts="ticketssold".concat(hidden); 
var v="value".concat(hidden);  
var openingbalance=parseFloat(document.getElementById(op).value);
var ticketssold=parseFloat(document.getElementById(ts).value); 
var value=parseFloat(document.getElementById(v).value); 
var totalsoldtickets=closingbalnce-openingbalance; 
var totalsoldtickets=(closingbalnce-openingbalance)*value;  
document.getElementById(ts).value=totalsoldtickets;
//document.name.ticketssold.value=total; 
alert("hiiii "+total);
 }

     <c:forEach items="${scratchlistlotto }" var="sl">
      <tr class="fontstyle">
        <td  class="table_color1"><input  name="scratchid" type="hidden"  class="table_color1" id="scratchid" style="text-align:center" size="2" value="${sl.scratchid }" />
        <input name="binid" type="text" readonly="readonly" class="table_color1" id="binid" style="text-align:center" size="2" value="${sl.bin }" /></td>
        <td class="table_color1"><input readonly="readonly" name="upccode" type="text" class="table_color1" id="upccode" style="text-align:center" size="25" readonly="readonly" value="${sl.upccode }" /></td>
        <td class="table_color2"  ><input readonly="readonly" name="totalticketss" type="text" class="table_color22" id="totalticketss${sl.i }" style="text-align:right" size="6" value="${sl.totaltickets }"/></td>
        <td class="table_color2"  ><input readonly="readonly" name="openingbalance${sl.i }" type="text" class="table_color22" id="openingbalance${sl.i }"   size="6" value="${sl.closingbalance }" /></td>
        <td><input name="closingbalnce" type="text" class="text_border" onclick="Click(${sl.i })" id="closingbalnce" onchange="javascript:Total(this.value)"   style="text-align:right" size="6" /></td>
        <td class="table_color2"><input readonly="readonly" name="value" type="text" class="table_color22" id="value${sl.i }" style="text-align:right" size="6" value="${sl.values }" /></td>
        <td class="table_color2"  ><input readonly="readonly" name="ticketssold" type="text" class="table_color22" id="ticketssold${sl.i }" style="text-align:right" size="6" /></td>
        <td class="table_color2"  ><input readonly="readonly" name="total" type="text" class="table_color22" id="total${sl.i }" style="text-align:right" size="6" /> 
        </td>
        <td width="38" align="center"><input name="endoflife" type="checkbox" class="text_border" id="endoflife"    /></td>
        </tr></c:forEach>
         <input type="hidden" name="hidden"  value="0"/>