CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   Please help me in getting different rowid's for newly added row (http://www.codingforums.com/showthread.php?t=255144)

ramuP 03-25-2012 11:59 AM

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,

devnull69 03-26-2012 07:41 AM

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.

Labrar 03-26-2012 07:29 PM

Why dont you use the DB Store functions itself? (Sorry for my bad english)
What do you try to make. Smartphoneapps?


All times are GMT +1. The time now is 12:51 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.