skip to Main Content

I have a row which has a add button.On click of add rows get added dynamically and on click of del rows will be deleted.
Row consists of collection of drop downs,text boxes.
One text box has to be prepopulated with a value based on user input in previous text box in the same row.

Able to prepopulate value in the textbox only for the first row.For the dynamic rows textbox is not getting prepopulated. Getting values from DB but not printing value in the textbox.

Following is my code:

$("tr.dynamicRow").each(function() {
    var studentCreate = $(this).find('#studentCreate').val();//textbox which gets added dynamically
    // AJAX to get values from DB and this works fine and the value is stored in result variable
    if (result != "" && result !=null) {                     
         $(this).find('#studentCreateNew').attr('value',result);//this doesn't work
    }
});

HTML code:

<tr class= "dynamicRow">
//some drop downs
    <div class="inputField">
        <td><b><bean:message key="label.student.create" />:</b></td>
        <td ><html:text property="studentCreate" name="studentForm" styleId="studentCreate" onchange="populateStudentCreate(this);" size="10" maxlength="6"  ></html:text></td>
    </div>
                                
    <div class="inputField">
        <td>    
            <b><bean:message key="label.student.create" />:</b>
        </td>
        <td><html:text property="studentCreateNew" name="studentForm" styleId="studentCreateNew" size="10" maxlength="6"></html:text></td>
//Add button
</tr>

Kindly help me with this.Thanks in advance.

2

Answers


  1. Instead of
    $(this).find('#studentCreate').attr('value',result);'
    you could try
    $(this).find('#studentCreate').append('<p>'+result+'</p>);

    Login or Signup to reply.
  2. Using #studentCreate is likely not what’s getting generated, or there are more than one of them. If you can assign a unique class to every element you want to target:

    $("tr.dynamicRow td input.studentCreate") 
    

    For instance, to select the input field directly. Then you don’t need to parse directly from the row.

    Additionally, question: the markup doesn’t list a TR around the TD tags, but a DIV. Is that the correct markup? Is there a sample where it includes the TR tab with the dynamicRow class?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search