www.webdeveloper.com
Results 1 to 2 of 2

Thread: Acessing dynamically generated elements?

  1. #1
    Join Date
    Jul 2006
    Posts
    1

    Acessing dynamically generated elements?

    Hi

    I have generated a webpage dynamically using struts tags, the page is basically a table with some numbers and some input fields on it.
    The page is generated from an ArrayList of objects using struts, and is indexed, meaning the name og the various fields I want to access comes in the following manner;

    <input type="text" name="arrayListname[0].customerName" ... etc

    Next row in the same table yields

    <input type="text" name="arrayListname[1].customerName" ... etc

    And so on, this works out beautifully with Struts on the server side, because the values are posted back into the arrayList, and I can continue to work with the elements with no hazzle.

    I have a problem though; I want a text field to be automatically updated with the sum of two other fields on the same row, say;
    <table>
    <tr>
    <td>109282</td>
    <td><input type="text" name="arrayListname[1].addValue" onchange=CalculateSums(this) ... etc</td>
    <td><input type="text" name="arrayListname[1].sum" ... etc</td>
    </tr>
    </table>

    When a user types something into the text field and leaves the fiield, I want the sum field to be calculated.
    Problem is, that I cannot for some reson refer to the name
    arrayListname[1].addValue, because javascript seem to think that I want to access some kind of array element (which it isn't really, on the html page anyways).

    We cannot generate an unique id for each element trough the struts tags as far as I understand.
    (For those familliar with struts, we are using an iterate tag which has a indexId="index" and is using <bean:write .. ... .. indexed="true" >)

    It is kinda tough to explain, but the core of my problem lies in accessing dynamically generated table elements and manipulate them at will.
    Is there any way to loop trough each tr and td element in a table and then hard code in some loop that will calculate stuff for me, without refering to names or id's in particular?

    Sorry for the more or less useless explanation, but any tips are apperciated.

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    Quote Originally Posted by znapper
    I cannot for some reson refer to the name
    arrayListname[1].addValue, because javascript seem to think that I want to access some kind of array element (which it isn't really, on the html page anyways).
    This will work correctly:

    document.forms["myFormName"].elements["arrayListname[1].addValue"].value

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles