Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble getting this script to work in IE/Firefox

Status
Not open for further replies.

rninja

Technical User
Apr 11, 2001
381
US
This works for the most part in IE. It creates new rows and deletes rows. Here are the problems:
1) the delete function doesn't delete the correct row intended.
2) Firefox does not work at all in terms of adding or deleting rows.

Here is the code thusfar:
Code:
 <form name="form1" method="POST" action="script.php">
    <input type="button" name="Button" value="Add Row" onClick="addRow()">
    <table cellspacing="0" cellpadding="0" border="0" id="dynatable">
      <thead>
        <tr>
          <td><strong>ID Number</strong></td>
          <td><strong>Notes</strong></td>
        </tr>
      </thead>
      <tbody id="TheBody">
        <tr>
          <td><input type="text" name="item1"></td>
          <td><input name="notes1" type="text" size="75"></td>
        </tr>
      </tbody>
    </table>
    <input type="submit" name="Submit" value="Add Item(s)">
    <input type="hidden" name="MM_insert" value="form1">
    <input name="numberRows" type="hidden" id="numberRows" value="1">
  </form>

<script language="JavaScript">
function addRow() {
var oRow;
var oCell1;
var oCell2;
var oCell3;
var newnumber;

newnumber = dynatable.rows.length;
oRow = dynatable.insertRow();
oCell1 = oRow.insertCell();
oCell1.innerHTML = "<input type='text' name='item" + newnumber + "'>";
oCell2 = oRow.insertCell();
oCell2.innerHTML = "<input name='notes" + newnumber + "' type='text' size='75'>";
oCell3 = oRow.insertCell();
oCell3.innerHTML = "<input type='button' name='Button2" + newnumber + "' value='remove Row' onClick='delRow()'>";
form1.numberRows.value++;
}

function delRow(){
    oRow=dynatable.deleteRow();
}
</script>

Does anyone have a fix or know what I can do to get this to work? I have been trying different things and not getting it to work right.

I appreciate any assistance with this!



Rninja

sl_sm.jpg

 
Referring simply to "dynatable" would probably not work in any browser other than IE. You should use the correct DOM method:

Code:
document.getElementById('dynatable')

instead.

As for the delete row not working - you are never specifying what row you wish to delete. deleteRow takes a parameter - the index of the row you wish to delete:


Hope this helps,
Dan


The answers you get are only as good as the information you give!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top