0

I'm trying to implement a dynamic input field on jQuery. But nothing is happening in this code. Somehow i believe the error is syntax related, or at least related to jquery fundamentals so i apologize in advance.

var add = function(){
    var intID = $('#target').length+1;
    var row = $('<tr id=\"row'+intID+'\">row</tr>');
    var data_1 = $('<td><input type=\"text\" name=\"part'.intID.'\"/></td>');
    var data_2 = $('<td><input type=\"text\" name=\"pos'.intID.'\"/></td>');
    var remove_button = $('<td><input type=\"button\" onclick=\"$(this).parent().parent().remove()\"/></td>');
    $(row).append(data_1);
    $(row).append(data_2);
    $(row).append(remove_button);
    $('#target').append(row);
}

The target is an empty table and im trying to add and remove the appropriate rows.

3
  • I'm not clear what the use of period '.' is for in your statements ...id=\"row'.intID.'\">r... should you use '+' to concat to a single string? Commented Oct 23, 2013 at 1:19
  • I fixed the concat error, but I still get no response from my code. Commented Oct 23, 2013 at 1:23
  • you've updated the question with one concat correction, but the two related to the input fields are still using the . Commented Oct 23, 2013 at 1:34

2 Answers 2

2

Your are concatenating incorrectly. .intID. should be +intID+.

Sign up to request clarification or add additional context in comments.

Comments

1

You should replace .intID. with +intID+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.