Results 1 to 1 of 1

Thread: Accessing Form Array Elements

  1. #1
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accessing Form Array Elements

    I am very new to javascript. I have a problem getting to any element from this form generated by the jsp page using struts. Please show me how to get to item[0].totalAmount for example, so that I can create a function to calculate the calculateTotal(). So far, when I do the alert, it is only valid up to
    document.myForm.item; the document.myForm.item[0] is invalid according to the alert. Any help is very much appreciated.

    Code:
    function calculateTotal(){
       alert(document.myForm.item);
    }
    <form name="myForm" method="post" action="/myAction.do">
      <table id="display" border="1">
         <tr>
         	<th scope="col" id="totalAmount">Total Amount</th>
         	<th scope="col" id="adjustmentAmount>Adjustment Amount</th>
         	<th scope="col" id="newAmount">NewAmount</th>
         </tr>
         <tr>
            <td><input type="text" name="item[0].totalAmount" id="totalAmount"  value="100" readonly="readonly"></td>
            <td><input type="text" name="item[0].adjustmentAmount" id="adjustmentAmount" 
                       value="" onblur="javascript:calculateTotal();" readonly="readonly"></td>
         	<td><input type="text" name="item[0].newAmount" id="newAmount" value="" readonly="readonly"></td>   
         </tr>
         <tr>
            <td><input type="text" name="item[1].totalAmount" id="totalAmount" value="350" readonly="readonly"></td>
            <td><input type="text" name="item[1].adjustmentAmount" id="adjustmentAmount" 
                            value="" onblur="javascript:calculateTotal();" readonly="readonly"></td>
         	<td><input type="text" name="item[1].newAmount" id="newAmount" value="" readonly="readonly"></td>   
         </tr>
      </table>
     </form>
    Last edited by Snookerman; 09-01-2009 at 06:22 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •