Reputation: 11
I want to add table rows dynamically using jQuery/Javascript and I have used the following code but it's not working in Chrome. Any help?
function AddTextBoxes(label,parameter, paraId) {
strCode += "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId +" value="+parameter.minValue + "-" + parameter.maxValue+ ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
}
Upvotes: 0
Views: 274
Reputation:
var myRow="<tr><td>my row</td></tr>";
$("#myTableId").append(myRow);
Upvotes: 0
Reputation: 6612
You need to initialize the strCode
and append
it to table
. Example
$('#tableId').append(strCode);
Updated Code:
function AddTextBoxes(label, parameter, paraId) {
var strCode = '';
strCode += "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId + " value=" + parameter.minValue + "-" + parameter.maxValue + ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
$('#tableId').append(strCode); // Change tableId with your table id
}
Upvotes: 0
Reputation: 8192
Here is the code with needed modifications. Also, you need to do somethign with the resulting string. For example append it to body. (untested)
function AddTextBoxes(label,parameter, paraId) {
var strCode = "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId +" value="+parameter.minValue + "-" + parameter.maxValue+ ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
document.body.innerHTML += strCode;
}
Upvotes: 0
Reputation: 4268
You need to append the contents of strcode which you are not doing in your function.
Also:-
You need to add var strCode = ''
before this line(At the beginning of the function):-
strCode += "<tr><td>";
Upvotes: 1