...

View Full Version : how to get the Dynamically(using javascript) generated values in Jsp to the form bean



murali1983
12-19-2006, 01:27 PM
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.

j9ine
12-19-2006, 08:03 PM
<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum