0

I am filling html table with following line of code

Javascript:

var newTR = document.createElement("TR");
var newTD;

    newTD = document.createElement("TD");
    newTD.width = "22%"

    newTD.innerHTML = "<input type='text' name='AppOrderTxt1' readOnly='true'"+  
     "' id='AppOrderTxt' value=' test'  class='text-noborders' onFocus='this.blur()' size='3'/>";

    newTR.appendChild(newTD);

    if(document.all){
        tblRCRPCombo.children[0].appendChild(newTR);
    }else{

       tblRCRPCombo.insertRow(tblRCRPCombo.rows.length);                           
       tblRCRPCombo.rows[tblRCRPCombo.rows.length-1].innerHTML=newTR.innerHTML;
    }

When i am trying to get the request parameter value by name AppOrderTxt1, it returns null in FireFox, while same thing is working in IE.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
chetan
  • 3,175
  • 20
  • 72
  • 113
  • Does the input appear in the HTML page? Does it work if you fix the syntax error (there is an extra quote before the id attribute)? – JB Nizet Feb 27 '12 at 08:36
  • i have remove that extra quote but it can't make any difference – chetan Feb 27 '12 at 09:10

2 Answers2

2

Might not be a problem but you have an extra ' in there:

newTD.innerHTML = "<input type='text' name='AppOrderTxt1' readOnly='true'"+  
     " id='AppOrderTxt' value=' test'  class='text-noborders' onFocus='this.blur()' size='3'/>";  

Also, the first if statement is working in firefox, but firefox won't enter that because of (document.all). If you only have this row...

tblRCRPCombo.children[0].appendChild(newTR);

...instead of the whole if else statement, then it will work in FF and IE.

Here's why: https://developer.mozilla.org/en/Mozilla_Web_Developer_FAQ

Some proprietary document objects such as document.all and document.layers are not part of the W3C DOM and are not supported in Mozilla. (There is partial undetectable support for document.all, though, in newer versions of Mozilla. However, that functionality only exists for compatibility with sites authored specifically for IE. You should not rely on Mozilla’s document.all support on new pages.) The method document.getElementById() can be used instead.

Niklas
  • 13,005
  • 23
  • 79
  • 119
  • I have remove that extra quote and if condition also but still it can't make any difference – chetan Feb 27 '12 at 09:13
  • http://jsfiddle.net/CvK5R/6/ This works for me in both FF 10 and IE 8. Might be a silly question but have you declared the `tblRCRPCombo` variable? – Niklas Feb 27 '12 at 09:15
-1

Replace innerHTML by textContent:

tblRCRPCombo.rows[tblRCRPCombo.rows.length-1].textContent = newTR.textContent;
itsmysterybox
  • 2,748
  • 3
  • 21
  • 26