Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Please help me in getting different rowid's for newly added row

    Hi everyone,

    I have a necessity to add records to a table (Grid) using javascript.

    I have a problem while deleting rows and adding new rows(Getting same rowid for last two rows) ...

    When creating new row i had taken existing rowCount, but when deleting in between row i am getting same rowid for the last two...


    Please help to overcome this issue...


    Here i am attached my sample code...

    Thanks in advance....

    var tab = document.getElementById("tabaddrow");
    var rc = tab.rows.length;
    var row = tab.insertRow(rc);
    var send = parseInt(rc) + 1;


    var cell0 = row.insertCell(0);
    var element0 = document.createElement("select");
    element0.id = "sel@" + send + "_1";
    element0.options[0] = new Option("--Select--", "0");
    element0.options[1] = new Option("Text Box", "1");
    element0.options[2] = new Option("Check Box", "2");
    element0.options[3] = new Option("Radio Button", "3");
    element0.options[4] = new Option("Password", "4");
    element0.options[5] = new Option("Select Box", "5");
    cell0.appendChild(element0);
    var onchangeFunction = new Function("", "var elem = document.getElementById('sel@" + send + "_1'); selectval('sel@" + send + "_1');");
    element0.onchange = onchangeFunction


    //*********code for deleting***********


    var table = document.getElementById("tabaddrow");
    var rowNumber = rowId.parentNode.parentNode.rowIndex;


    var agree = confirm("Are you sure you wish to delete the row?");
    if (agree) {

    if (parseInt(document.getElementById("tabaddrow").rows.length) > 0) {

    //alert(document.getElementById("tabaddrow").rows.length);
    document.getElementById("tabaddrow").deleteRow(rowNumber);


    }


    }


    Thanks in advance,

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Why don't you just store the highest id number in a (global) variable and increase this variable while creating a new row? This way you won't have double entries.

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    61
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Why dont you use the DB Store functions itself? (Sorry for my bad english)
    What do you try to make. Smartphoneapps?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •