Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:38:27+00:00 2026-05-28T00:38:27+00:00

What I require is a pretty standard feature. And I am sure its easy

  • 0

What I require is a pretty standard feature. And I am sure its easy enough, but somehow I cant make it happen. Please help me out here.

This is the scenario–>

I have a struts form on a jsp, which takes in employee information. Now with every employee I want to associate some family members.

So for information of family members I want :

1.) A row of — 1 select element and 3 text field elements — in the end of the form.

2.) A ‘add’ button which appends such rows on demand for adding more family members.

I dont know how I can attach a screen shot to give you exact idea of what I want.

I have tried doing this, using javascript, but javascript adds standard HTML elements, because of which I am not able to access the value of those fields in my action class.(Please tell me if this is not the case, because then the only question that will remain is, why am I unable access those values)

Currently what I am trying:

JSP:

<s:form name="enterEmployeeInfo" id="enterEmployeeInfo" action="enterEmployeeInfo">

    ////OTHER FORM ELEMENTS//////////////

        <table>
        <tr>
            <td>Relationship</td>
            <td>Name</td>
            <td>Age</td>
            <td>Occupation</td>
        </tr>
        <tr>
            <td>
                <select name="rel">
                    <option value=""></option>
                    <option value="Father">Father</option>
                    <option value="Mother">Mother</option>
                    <option value="Spouse">Spouse</option>
                    <option value="Child">Child</option>
                </select>
            </td>
            <td> <input name="rName[]"/></td>
            <td> <input name="rAge"/>          </td>
            <td> <input name="rOccupation"/>   </td>
            <td colspan="4" align="right"><button type="button" onclick="tryFunc(this.parentNode);">Add</button></td>
        </tr>
        </table>
        <s:submit value="Add Employee" name="submit"/>
        <s:reset  value="Reset"       name="reset"/>
</s:form>

The JS:

function tryFunc(node){
    var root = node.parentNode.parentNode;
    var allRows = root.getElementsByTagName('tr');
    var cRow = allRows[1].cloneNode(true);
    var cInp = cRow.getElementsByTagName('input');
    for(var i=0;i<cInp.length;i++){
        cInp[i].setAttribute('name',cInp[0].getAttribute('name')+'_'+(allRows.length+1))
    }
    var cSel = cRow.getElementsByTagName('select')[0];
    cSel.setAttribute('name',cSel.getAttribute('name')+'_'+(allRows.length+1));
    root.appendChild(cRow);
}

With this I am able to add a new row of specified elements, but unable to access the field values in the action class. I would like to point out that I am not able to access even the first row’s elements in action class (probably because they are standard HTML).

Any help is appreciated.

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:38:28+00:00Added an answer on May 28, 2026 at 12:38 am

    here is the solution to the problem, for those still stuck on it.

    In the jsp:

    <s:form name="enterEmployeeInfo" id="enterEmployeeInfo" action="enterEmployeeInfo">
    
        ////OTHER FORM ELEMENTS//////////////
    
            <table>
                <tr>
                    <td align="center">Relationship</td>
                    <td align="center">Name</td>
                    <td align="center">Age</td>
                    <td align="center">Occupation</td>
                </tr>
                <tr>
                    <td>
                        <select name="rel">
                            <option value=""></option>
                            <option value="Father">Father</option>
                            <option value="Mother">Mother</option>
                            <option value="Spouse">Spouse</option>
                            <option value="Child">Child</option>
                        </select>
                    </td>
                    <td> <input name="rName"/></td>
                    <td> <input name="rAge"/>          </td>
                    <td> <input name="rOccupation"/>   </td>
                </tr>
                <tr>
                    <td colspan="4" align="right"><button type="button" onclick="tryFunc(this.parentNode);">Add</button></td>
                </tr>
            </table>
            <s:submit value="Add Employee" name="submit"/>
            <s:reset  value="Reset"       name="reset"/>
    </s:form>
    

    The JS:

    function tryFunc(node){
        var root = node.parentNode.parentNode;
        var allRows = root.getElementsByTagName('tr');
        var cRow = allRows[1].cloneNode(true);
        root.appendChild(cRow);
    }
    

    Then in the action class, just define a variables like this:

        private String rel[];
        private String rName[];
        private String rAge[];
        private String rOccupation[];
    

    Define their getters and setters, and you can access each element of each row in jsp like this :

        rel[0], rel[1], ........
        rName[0],rName[1], .......
        etc......
    

    As for copying the Value of select element to cloned row, its simple javascript. Just do this:

        clonedSelect.selectedIndex = original.selectedIndex;
    

    If you still have issues, comment. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
Pretty simple but specific question here: I'm not entirely familiar with the JPEG standard
My problem: require_once '/includes/aws-sdk-1.5.2/sdk.class.php'; My environment: I have a pretty standard PHP site that
I am involved in a personal project which will require pretty extensive knowledge of
Using Require.js and it works pretty solid. However, I'm reading about optimization (http://requirejs.org/docs/optimization.html) using
Require a huge help here, since this is affecting our production instance. One of
require_once('/recaptcha/recaptchalib.php'); was in the correct place but the error says: Warning: require_once() [function.require-once]: open_basedir
I know what are you saying already (baad idea), but please read first :)
I have some large .png (.jpg, ...) files that require pretty much a full
I'm beginning a project right now that will require a pretty extensive web back

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.