Can some fix this code? Delet table rows.

Discussion in 'Javascript' started by Spanky, Sep 6, 2003.

  1. Spanky

    Spanky Guest

    Thanks for any help in advance!

    I have this order form where you add rows as you need them. The
    routine to add fields is working fine. I am trying to add the ability
    to delete rows if you check the checkbox in the cooresponding field
    and click remove item.

    I would appreciate any insite. BTW Am using IE browsers only.

    Thanks!




    <SCRIPT LANGUAGE="JScript">
    var oRow;
    var box;
    var itemquantity;
    var itemdescription;
    var itemtax;
    var itemprice;
    var itemserial;

    function addvalue(f)
    {
    var oCell;
    var i, j;
    var check="";

    // Insert rows and cells into the first body.

    //Get the current row count. Then change item name number
    for(i=0; i<1;i++)
    {

    //Get the row count to make distinct field names
    varItem=oTable.rows.length;

    //Start Entering At Top Of Table
    oTBody0.scrollTop=true;

    //Insert A New Row
    oRow = oTBody0.insertRow();

    //Insert New Action Cell
    oCell = oRow.insertCell();
    box = "<INPUT type=checkbox class=checkbox name=checkbox id=chkBX
    value=check >";
    oCell.innerHTML = box

    //Insert New Quantity Cell
    oCell = oRow.insertCell();
    itemquantity = "<input type=text size=8 name=ItemQuantity_"
    +varItem+ ">";
    //itemquantity = "<input type=text name=Item_Quantity_1 size=8>";
    oCell.innerHTML = itemquantity

    //Insert New Description Cell
    oCell = oRow.insertCell();
    itemdescription = "<input type=text size=60 name=ItemDescription_"
    +varItem+ ">";
    oCell.innerHTML = itemdescription

    //Insert New Serial Cell
    oCell = oRow.insertCell();
    itemserial = "<input type=text size=12 name=ItemSerial_" +varItem+
    ">";
    oCell.innerHTML = itemserial

    //Insert Unit Price Cell
    oCell = oRow.insertCell();
    itemprice = "<input type=text size=9 name=ItemPrice_" +varItem+
    ">";
    oCell.innerHTML = itemprice

    //Insert New Tax Cell
    oCell = oRow.insertCell();
    itemtax = "<input type=text size=3 name=ItemTax_" +varItem+ ">";
    oCell.innerHTML = itemtax
    }
    }
    function removevalue()
    {
    if(oTable.rows.length>0)
    {
    for(var i=7; i<(oTable.rows.length+7); i++)
    {
    alert(oTable.rows.length)
    alert(document.forms[0].elements.value+" ALERTING")
    if(document.forms[0].elements.checked==true)
    {
    alert(oTable.rows.length)
    //oRow.sectionRowIndex=i;
    alert(box.value+"oooooooooooooooooo")
    oTable.deleteRow(oTable.rows)
    }
    }
    }
    }
    </script>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <form action="" name="test" id="test">
    <tr>
    <td width="100%" colspan="100%">
    <input type="button" name="add" value="Add Item" class="button"
    onClick="addvalue(this.form)">
    <input type="button" name="remove" value="Remove Item"
    class="button" onClick="removevalue(this)">
    </td>
    </tr>
    </table>
    <BR>
    <table width="100%" border="0" cellspacing="0" cellpadding="0"
    id="oTable">
    <TBODY ID="oTBody0">
    <tr>
    <td class="label">&nbsp;</td>
    <td class="label">Quantity:</td>
    <td class="label">Item:</td>
    <td class="label">Serial:</td>
    <td class="label">Unit Price:</td>
    <td class="label">Tax:</td>
    </tr>
    </TABLE>
    </FORM>

     
    Spanky, Sep 6, 2003
    #1
    1. Advertisements

  2. "Spanky" <> schreef in bericht
    news:...
    >
    > I have this order form where you add rows as you need them. The
    > routine to add fields is working fine. I am trying to add the ability
    > to delete rows if you check the checkbox in the cooresponding field
    > and click remove item.
    >


    This ought to do it:

    function removevalue(form) {
    var checkboxes = form.elements['checkbox'];
    if (!checkboxes) return;
    for (var i = 0; i < checkboxes.length; i++) {
    if (checkboxes.checked) {
    document.getElementById('oTBody0').deleteRow(i + 1);
    removevalue(form);
    }
    }
    }

    Call it the same way as you call addvalue()


    JW
     
    Janwillem Borleffs, Sep 6, 2003
    #2
    1. Advertisements

  3. Spanky

    Spanky Guest

    "Janwillem Borleffs" <> wrote in message news:<3f59c4a9$0$28895$>...
    > "Spanky" <> schreef in bericht
    > news:...
    > >
    > > I have this order form where you add rows as you need them. The
    > > routine to add fields is working fine. I am trying to add the ability
    > > to delete rows if you check the checkbox in the cooresponding field
    > > and click remove item.
    > >

    >
    > This ought to do it:
    >
    > function removevalue(form) {
    > var checkboxes = form.elements['checkbox'];
    > if (!checkboxes) return;
    > for (var i = 0; i < checkboxes.length; i++) {
    > if (checkboxes.checked) {
    > document.getElementById('oTBody0').deleteRow(i + 1);
    > removevalue(form);
    > }
    > }
    > }
    >
    > Call it the same way as you call addvalue()
    >
    >
    > JW




    PERFECT!!! Thanks JW
     
    Spanky, Sep 7, 2003
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,392
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Subba Rao via DotNetMonster.com

    script for moving rows up and down and traverse thru rows of HTML table

    Subba Rao via DotNetMonster.com, Mar 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    8,943
    Subba Rao via DotNetMonster.com
    Mar 19, 2005
  3. Peter Rilling
    Replies:
    1
    Views:
    577
    Lucas Tam
    May 11, 2005
  4. Xah Lee
    Replies:
    22
    Views:
    1,540
    Tim Roberts
    Mar 21, 2006
  5. Rio
    Replies:
    4
    Views:
    1,476
  6. Xah Lee
    Replies:
    23
    Views:
    1,433
    Tim Roberts
    Mar 21, 2006
  7. Mark
    Replies:
    2
    Views:
    535
    Allen Chen [MSFT]
    Jan 21, 2009
  8. Xah Lee
    Replies:
    21
    Views:
    1,187
    Tim Roberts
    Mar 21, 2006
Loading...