I need to generate the table rows dynamically when ever the user clicks add more contacts on the page. However I am able to read the data from the dynamically generated fields right now as it is html and on the browser. But, I want to take the data from the fields and send it to the my action class which will further do the further processing of calling a webservice and …
So, what should I do to make sure that data from the fields goes to the action class. I am using struts2… please help. I have attached the html out of the page for you guys to test and see the flow.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Notification Services</title>
<link rel="stylesheet" type="text/css" href="style.css" /></head>
<SCRIPT type="text/javascript">
function toggleDisplay(attachments){
element = document.getElementById('attachments').style;
if (element.display=='none') {element.display='block';}
else {element.display='none';}
}
var max = 0; // maximum # of attachments allowed
var currentUploads = 0; // current # of attachment sections on the web page
var scrollPosVert = 0; // stores the current scroll position on the form
// for some reason when a div is taken out, the form
// will scroll to the top on both Firefox and IE
// SCROLL FUNCTIONS
function saveScrollPos(offset)
{
scrollPosVert=(document.all)?document.body.scrollTop:window.pageYOffset-offset;
}
function setScrollPos()
{
window.scrollTo(0, scrollPosVert);
setTimeout('window.scrollTo(0, scrollPosVert)',1);
}
function addUpload(maxUploads)
{
/*max = Number(maxUploads);
currentUploads++;
if (currentUploads>max) return;
if (currentUploads>0)
document.getElementById('addupload').childNodes[0].data='Add more contacts';
if (currentUploads==max) document.getElementById('addupload').childNodes[0].data='Max level reached';
alert(document.getElementById("attachment").getElementsByTagName('checkbox').value);
// First, clone the hidden attachment section
var newFields = document.getElementById('attachment').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
//alert(newField.length);
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + currentUploads;
//alert(newField[i].innerHTML);
}
// Insert our new Attachment section into the Attachments Div
// on the form...
var insertHere = document.getElementById('attachmentmarker');
insertHere.parentNode.insertBefore(newFields,insertHere);*/
max = Number(maxUploads);
currentUploads++;
if (currentUploads>max) return;
if (currentUploads>0)
document.getElementById('addupload').childNodes[0].data='Add more contacts';
if (currentUploads==max) document.getElementById('addupload').childNodes[0].data='Max level reached';
// First, clone the hidden attachment section
var newChec = document.getElementById('chec').cloneNode(true);
newChec.id = newChec.id + currentUploads;
var newFile = document.getElementById('file').cloneNode(true);
newFile.id = newFile.id + currentUploads;
var newDesc = document.getElementById('desc').cloneNode(true);
newDesc.id = newDesc.id + currentUploads;
// Insert our new Attachment section into the Attachments Div
// on the form...
document.getElementById('attachmentmarker').appendChild(newChec);
document.getElementById('attachmentmarker').appendChild(newFile);
document.getElementById('attachmentmarker').appendChild(newDesc);
}
function getVal() {
for(var i=1; i<=currentUploads; i++) {
alert(document.getElementById('chec'+i).checked);
alert(document.getElementById('file'+i).value);
alert(document.getElementById('desc'+i).value);
}
}
</SCRIPT>
<body id="body1">
<div id="wrapper">
<div id="container1">
<div id=wrapper_vin>
<div id="padding_container">
<div id="header2">
<div id="header1"><h3 style="color:white;">NOTIFICATIONS</h3></div>
<P align="left"><font face="Times New Roman, Times, serif">Find out immediately if there is an issue with your vehicle,
such as an attempted break-in or a red alert in your OnStar Vehicle
Diagnostics report. Simply enroll in our notifiaction services and we'll let you know right away via your preferred You can edit your preferences and contacts at any time after enrolling.
</font></P>
</div>
<div id="wrapper1">
<div id="navigation1" align="center" ><b>Theft Notifications</b><br>
<a href="javascript:toggleDisplay('attachments')"><b>Enroll Now</b></a>
</div>
<div id="content1">
<p align="left"><strong>Opt In Theft Notifications</strong><br>
Some text to simplifySome text to simplifySome text to simplifySome text to simplifySome text to simplify
Some text to simplifySome text to simplifySome text to simplify<br>
<a href="#">Read Sample Email</a>, <a href="#">Read SAmple TEXT/SMS</a>, <a href="#">Hear Sample Voicemail</a></p>
</div>
</div>
<form>
<div id="attachment" style="display:none">
<table>
<tr>
<td><input type="checkbox" id="chec" name="chec" value='' /></td>
<td><select id="file" name="file">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select></td>
<td ><input type="text" id="desc" name="desc" value='' /></td></tr>
</table>
</div>
</form>
<div id="attachments" class="container" style="display:none">
<table><tr><td width="15%"><strong>On/Off</strong></td>
<td width="25%"><strong>Contact</strong></td>
<td width="35%%"><strong>Information</strong></td>
</tr></table>
<!-- <div id="attachmentssub" >
<input type="checkbox" id="chec" name="chec" value='' />
<select id="file" name="file">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select><
<input type="text" id="desc" name="desc" value='' />
<a href="#" onclick="javascript:removeFilelast(this.parentNode.parentNode,this.parentNode);">Delete</a> not required
</div><br>-->
<span id="attachmentmarker"></span>
<a id="addupload" style="floar:left;" href="javascript:addUpload(4)">Add Contact Information</a>
<table style="float:right;"><tr><td><input type=button class="buttonStyle" name="" value="save" onClick="javascript:getVal()"></td>
<td><input type=button class="buttonStyle" name="" value="cancel" onClick=""></td></tr></table>
</div>
<div id="wrapper11">
<div id="OVD" align="center" >OVD Notifications<br>
<a href="#">Enroll Now</a></div>
<div id="OVD_content">
<h2>Content</h2>
<p>Some sample content, add your own here</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>