Geek
Geek

Reputation: 11

jQuery/Javascript code not working in Chrome and Firefox

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

Answers (4)

user2587132
user2587132

Reputation:

var myRow="<tr><td>my row</td></tr>";
$("#myTableId").append(myRow);

Upvotes: 0

Manoj Yadav
Manoj Yadav

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

sabof
sabof

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

Vivek Sadh
Vivek Sadh

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

Related Questions