Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to get the Dynamically(using javascript) generated values in Jsp to the form bean

    how to get the Dynamically(using javascript) generated values in Jsp to the form bean(struts)...

    scenario...is shown below.
    <div>
    <table id='TABLE1'>
    <thead>----------</thead>
    <tbody>
    </tbody>
    </table>
    </div>

    i am using the table id in my java script and dynamically adding the rows with in the tbody......

    as shown below...
    ------------------------------------------------------------------
    var invoiceTable = document.getElementById('TABLE1');
    row=invoiceTable.tBodies[0].appendChild(document.createElement('<tr>'));
    cell=document.createElement('td');
    row.appendChild(cell);
    ---------------------------------------------------------------
    with in each <td> i am adding a text box..

    onClick on submit button i should be able to capture the values that are entered in the textbox by the user.., i got to get the values in the form bean.

    plz...help me...i am in terrible need of it..

    thnx
    murali.
    Last edited by murali1983; 12-19-2006 at 03:24 PM.

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script>
    var tbody = document.getElementById('TABLE1');
    var tr = document.createElement('tr');
    var td = document.createElement('td');
    var textbox = document.createElement('textarea');
    textbox.setAttribute('width','300');
    textbox.setAttribute('height','100');
    
    td.appendChild(textbox);
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    function getValues() {
       var values = [];
       var text = document.getElementsByTagName('textarea');
       for (var i=0; i<text.length; ++i) {
          values.push(text[i].value);
       }
       alert(values);  //the values array will contain the text from each textarea element
    }
    </script>
    
    <div>
    <form onsubmit="getValues()">
    <table>
    <thead>----------</thead>
    <tbody id="TABLE1">
    </tbody>
    </table>
    <br>
    <input type="submit" value="Submit">
    </form>
    </div>
    Last edited by j9ine; 12-19-2006 at 09:07 PM.


  •  

    Posting Permissions

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