troubleshooting Question

how to handle multiple html text with same name in struts

Avatar of swapna84
swapna84 asked on
JavaJavaScriptJSP
6 Comments1 Solution528 ViewsLast Modified:
Hello Every one,
I have a HTML table with dynamic rows. I can add additional row and remove it when needed. The first row is however static and cannot be removed. I'm using a combination of javascript DJOM, and struts in my jsp page. Everything seems to be working. However the problem is when I do my validation, I'm not sure how to capture the individual elements back in my error page, because it the field is returned something like '[Ljava.lang.String;@2ee4e8' instead of the individual value. Can someone help me how I can proceed on this. Any help will be highly appreciated.
<script>
	function addNewRow(in_tbl_name)
	{
		var tbody = document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
	  	var tableRowCount = document.getElementById(in_tbl_name).rows.length;
	  	if(tableRowCount >6)
	  		return;
		// create row
		var row = document.createElement("TR");
		//create the five columns for this row
		var fNameCol = document.createElement("TD");
	  	var lastNameCol = document.createElement("TD");
		var removeCol = document.createElement("TD");
		/*add table contents*/
		fNameCol.innerHTML = '<html:text name="custform" property="customerFirstName" size="20" maxlength="16" />';  
		lastNameCol.innerHTML = '<html:text name="custform" property="customerFirstName" size="20" maxlength="16" />';
		removeCol.innerHTML = '<a href=\"#\" onClick=\"delRow()\" >remove</a>';
		
		/*add class Name*/
		fNameCol.className = "tablebody"; 
		lastNameCol.className = "tablebody"; 
		removeCol.className="tablebody";
		
		/*add width for the columns*/
		fNameCol.width = "130"; 
		lastNameCol.width = "130"; 
		removeCol.width ="160";
		// append data to row
		row.appendChild(fNameCol);
		row.appendChild(lastNameCol);
		row.appendChild(removeCol);

		// add to count variable
		count = parseInt(count) + 1;
		// append row to table
		tbody.appendChild(row);
	}

	  function delRow()
	  {
	    var current = window.event.srcElement;
	    //here we will delete the line
	    while ( (current = current.parentElement)  && current.tagName !="TR");
	         current.parentElement.removeChild(current);
	  }


</script>

<table id="custtab" class="form" cellspacing="0">
	<tr>
		<td class="tablebody" width="130">First Name</td>
		<td class="tablebody" width="130">Last Name</td>
		<td class="tablebody" width="160"><a href="#" onclick="addNewRow('custtab');">add another Customer</a> </td>
	</tr>
	<tr>
		<td class="tablebody" width="130"><html:text name="custform" property="customerFirstName" size="20" maxlength="20" /></td>
		<td class="tablebody" width="130"><html:text name="custform" property="customerLastName" size="20" maxlength="20" /></td>
		<td class="tablebody" />
	</tr>
</table>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros