Mozilla, innerHTML question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mitch

    Mozilla, innerHTML question.

    Here is some code I have bastardised from a few places, Obviously the
    innerHTML coding won't work in Mozilla, could anyone suggest a work
    around or fix?

    cheers,
    Mitch.
    *************** *snip********** ***************
    <html>
    <head>
    <title>Untitled </title>
    <script>
    var rowNum = 0;
    function addRow(rowCount ){
    var theTab = document.getEle mentById('accTa b');
    var blankRow = theTab.rows[0];
    for(r=0;r<rowCo unt;r++){
    var newRow = theTab.insertRo w();
    for (i=0; i < blankRow.cols; i++) {

    newRow.insertCe ll().innerHTML =
    blankRow.cells[i].innerHTML.repl ace(/\#/g, rowNum++);

    }
    }

    }
    </script>
    </head>
    <body onLoad='addRow( 5);'>
    <table cellpadding="0" cellspacing="0" width="100%" id="accTab"
    border="1">
    <tr style="display: none" class="altRow" cols=6>
    <td align="center"> <input maxlength="20" size="13"
    name="c_code1" ></td>
    <td align="center"> <select name=duty1><opt ion value=""
    rate="">Please select</option></select></td>
    <td align="center"> <input maxlength="4" size="2" ></td>
    <td align="center"> <input maxlength="4" size="2" ></td>
    <td align="center"> <input maxlength="8" size="5" ></td>
    <td align="center"> <input maxlength="8" size="7" ></td>
    </tr>
    <tr>
    <th align="left">fi eld1<span class="required Field">*</span></th>
    <th align="left">se lect1 <span class="required Field">*</span></th>
    <th align="left">fi eld2<span class="required Field">*</span></th>
    <th align="left">fi eld3<span class="required Field">*</span></th>
    <th align="left">fi eld4</th>
    <th align="left">fi eld5</th>
    </tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="100%" border="1">
    <tr>
    <td colspan="6"><in put type=button value='Add Item'
    onClick="addRow (1)"></td>
    </tr>
    </table>
    </body>
    </html>
    *************** *************** ***snip******** *************** *****
  • DU

    #2
    Re: Mozilla, innerHTML question.

    Mitch wrote:[color=blue]
    > Here is some code I have bastardised from a few places, Obviously the
    > innerHTML coding won't work in Mozilla, could anyone suggest a work
    > around or fix?
    >[/color]

    Your HTML markup code first need several fixes.
    [color=blue]
    > cheers,
    > Mitch.
    > *************** *snip********** ***************
    > <html>
    > <head>
    > <title>Untitled </title>
    > <script>
    > var rowNum = 0;
    > function addRow(rowCount ){
    > var theTab = document.getEle mentById('accTa b');
    > var blankRow = theTab.rows[0];
    > for(r=0;r<rowCo unt;r++){
    > var newRow = theTab.insertRo w();[/color]

    I believe this won't work. insertRow needs a parameter.
    "index of type long
    The row number where to insert a new row. This index starts from 0
    and is relative to the logical order (not document order) of all the
    rows contained inside the table."


    Also, creating several rows in a for loop won't work in MSIE 6.


    [color=blue]
    > for (i=0; i < blankRow.cols; i++)[/color]

    cols is not a valid attribute of an referenced table row. cells.length
    is though.


    for(var CellIterator = 0; CellIterator < blankRow.cells. length;
    CellIterator++)
    would be ok though.

    {[color=blue]
    >
    > newRow.insertCe ll().innerHTML =
    > blankRow.cells[i].innerHTML.repl ace(/\#/g, rowNum++);[/color]

    Same thing here. insertCell() needs a parameter and only once the
    returned value has been achieved into another objRefCell, then you can
    "edit" the content of that cell accordingly.

    var objTCell = newRow.insertCe ll(i);
    if(objTCell.tag Name == "TD") {objTCell.first Child.nodeValue = "text node
    value";};
    or
    if(objTCell.nod eType == 1) {objTCell.first Child.nodeValue = "text node
    value";};

    "index of type long
    The place to insert the cell, starting from 0."

    [color=blue]
    >
    > }
    > }
    >
    > }
    > </script>
    > </head>
    > <body onLoad='addRow( 5);'>
    > <table cellpadding="0" cellspacing="0" width="100%" id="accTab"
    > border="1">
    > <tr style="display: none" class="altRow" cols=6>[/color]


    cols=6 is invalid html.

    [color=blue]
    > <td align="center"> <input maxlength="20" size="13"
    > name="c_code1" ></td>
    > <td align="center"> <select name=duty1><opt ion value=""
    > rate="">[/color]


    1- rate="" is an invalid html attribute.
    2- select can not exist without a wrapping form element.


    Please select</option></select></td>[color=blue]
    > <td align="center"> <input maxlength="4" size="2" ></td>
    > <td align="center"> <input maxlength="4" size="2" ></td>
    > <td align="center"> <input maxlength="8" size="5" ></td>
    > <td align="center"> <input maxlength="8" size="7" ></td>
    > </tr>
    > <tr>
    > <th align="left">fi eld1<span class="required Field">*</span></th>
    > <th align="left">se lect1 <span class="required Field">*</span></th>
    > <th align="left">fi eld2<span class="required Field">*</span></th>
    > <th align="left">fi eld3<span class="required Field">*</span></th>
    > <th align="left">fi eld4</th>
    > <th align="left">fi eld5</th>
    > </tr>
    > </table>
    > <table cellpadding="0" cellspacing="0" width="100%" border="1">
    > <tr>
    > <td colspan="6"><in put type=button value='Add Item'
    > onClick="addRow (1)"></td>
    > </tr>
    > </table>
    > </body>
    > </html>
    > *************** *************** ***snip******** *************** *****[/color]

    You should validate your document ( http://validator.w3.org/ ): DOM2
    HTML methods work best when the document markup syntax is perfectly valid.

    Working example in Mozilla-based browsers, MSIE 6 for Windows, Opera 7.x:
    Dynamically creating, populating and inserting a table


    DU
    --
    Javascript and Browser bugs:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    • mitchel Turner

      #3
      Re: Mozilla, innerHTML question.

      Thanks for the reply but I have already fixed the problem, Turns out
      Mozilla doesn't like insertCell().

      BTW the stuff you have pointed out as HTML errors are either being used
      or generated by other parts of my app.

      Should I post the entire page next time? or just the information
      pointent to the question?


      Mitch.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • DU

        #4
        Re: Mozilla, innerHTML question.

        mitchel Turner wrote:
        [color=blue]
        > Thanks for the reply but I have already fixed the problem, Turns out
        > Mozilla doesn't like insertCell().
        >[/color]

        That is not my conclusion. In some specific context, insertCell(inde x)
        will not work in MSIE 6 for Windows but, as far as I can see,
        insertCell(inde x) will always work accordingly in Mozilla.
        [color=blue]
        > BTW the stuff you have pointed out as HTML errors are either being used
        > or generated by other parts of my app.
        >
        > Should I post the entire page next time? or just the information
        > pointent to the question?
        >
        >
        > Mitch.
        >[/color]

        An url is always better, more convenient.

        DU
        --
        Javascript and Browser bugs:

        - Resources, help and tips for Netscape 7.x users and Composer
        - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


        Comment

        • Dr John Stockton

          #5
          Re: Mozilla, innerHTML question.

          JRS: In article <bk8gmj$eie$1@n ews.eusc.inter. net>, seen in
          news:comp.lang. javascript, DU <drunclear@ho t-R-E-M-O-V-E-mail.com>
          posted at Tue, 16 Sep 2003 22:25:19 :-[color=blue]
          >mitchel Turner wrote:[/color]
          [color=blue][color=green]
          >> Should I post the entire page next time? or just the information
          >> pointent to the question?[/color][/color]
          [color=blue]
          >An url is always better, more convenient.[/color]

          Not so. It is not convenient for those who read News off-line.

          What is best is for the questioner is to develop a minimum example of
          the problem, or to remove extraneous parts from the page which has the
          problem, testing at each step (that often reveals the answer). Once the
          problem is localised, then if what remains is reasonably small it can be
          posted here for all to see and otherwise its URL can be given.

          That is as stated in the FAQ, more or less.
          [color=blue]
          >DU
          >--[/color]

          DSS.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

          Comment

          Working...