File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Javascript and struts 2 problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Javascript and struts 2 problem" Watch "Javascript and struts 2 problem" New topic
Author

Javascript and struts 2 problem

Ajith KR
Greenhorn

Joined: Apr 23, 2008
Posts: 1
Hi All,

I have a form, with 5 elements. When the user clicks on the "ADD ROW" button, the above elements should be replicated and show on the page. I was able to achieve this using DOM Component, in a plain html and javascript mode.

Here is the portion of javascript which I used to achieve the above.

var tableName = document.getElementByIdd('addRow);
var lastRow = tableName.rows.length;
var row = tableName.insertRow(lastRow);
var i = lastRow-1; //Subtracting the header row from the count

var input1 = row.insertCell(0)
var element1 = document.createElement('input');
element1.type='text';
element1.name='name'+i;
input1.appendChild(element1);

The problem started when I tried to use this code in JSP with struts2 tags. I converted the regular html form tags into struts tags. Now When I use the above javascript, it shows up the row but it cannot add it to the table.

I couldn't find a solution for this. Any advice is helpful.

Thank you,
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Welcome to the JavaRanch.
You must have missed our name policy on the way in. In short, your displayed name must be a real sounding first and last name, separated by a space. You can change it here.
As for your question, I notice you are missing a single quote character in your first line of code.
If that's a typo, please Post Real Code.
The first step you should take is to view the source of the JSP page as it appears in a browser to make sure the HTML element names are correct.
Firefox has a Javascript Console and debugger that are very useful when trying to solve these kinds of problems.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Javascript and struts 2 problem
 
Similar Threads
Adding Dynamic Rows to Table using addrow button
adding and deleting a row in html
How to set multiple parametes in a form
how to delete multiple browse
Add Rows dynamically to a table