ADD/DEL Row
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dariusz_Tybor
Posted On:   Tuesday, March 25, 2003 07:17 AM

I got this script from Scriptbreaker.com, it allws me to add and delete rows. What I want it to do is: insert row in any position exemple: lets say i already added tow rows and I wanted to add one more row right after the first one. here is the example: row1 insert new row here row 2 row 3 thank you int i=1; Number Article Count var max = 10 //maximum rows var color = "red"; var selected_r   More>>

I got this script from Scriptbreaker.com, it allws me to add and delete rows. What I want it to do is:

insert row in any position exemple: lets say i already added tow rows and I wanted to add one more row right after the first one.

here is the example:

row1
insert new row here
row 2
row 3

thank you




			
int i=1;

















Number Article Count







");

function end_color()
{
if (selected_row != 0)
{
object = eval("row"+selected_row);
object.style.backgroundColor ='white';
}
}

function setcolor()
{
index = 'row1'
object = eval(index);
object.style.backgroundColor = "red";
}

function addrow()
{
// count the number of rows from a table
numrows = document.all.project_table.rows.length;
if (numrows == max + 1)
{
alert("You can only add "+ max + " articles!");
}
else
{
var newRow = document.all.project_table.insertRow(numrows);
document.project.count.value = numrows;
(newRow.insertCell()).innerHTML = ""+numrows+"";
name = "lst_list" + numrows;
(newRow.insertCell()).innerHTML = " ";
name = "txt_count" + numrows;
(newRow.insertCell()).innerHTML = " ";
project_table.rows.item(numrows).id = "row" + numrows;
project_table.rows.item(numrows).name = "row" + numrows;
funct_name = eval("funct_row" + numrows);
row_name = eval("row"+numrows);
row_name.attachEvent("onclick",funct_name);
}
}

function deleter()
{
numrows = document.all.project_table.rows.length;
if (numrows != 1)
{
if(selected_row == 0)
{
project_table.deleteRow(numrows-1);
document.project.count.value = numrows - 2;
}
else
{
getval(selected_row);
project_table.deleteRow(selected_row);
changef(selected_row);
document.project.count.value = numrows - 2;
}
}
selected_row = 0;
alert("You can only add "+numrows+ " articles!");
}

function changef(index)
{
numrows = document.all.project_table.rows.length;
numrows = numrows + 1;
for(i = index + 1;i
{
plus = i+1
min = i-1;
row_name = eval("row" + i);
row_name.cells(0).innerHTML = ""+ min +"";
row_name2 = "row" + min;
funct_name = eval("funct_row" + i);
row_name.detachEvent("onclick",funct_name);
row_name.name = row_name2;
row_name.id = row_name2;
funct_name = eval("funct_row" + min);
row_name2 = eval(row_name2);
row_name2.attachEvent("onclick",funct_name);
}
}

function getval(index)
{
numrows = document.all.project_table.rows.length;
numrows = numrows -1;
for (i = index;i < numrows;i++)
{
obj_list = eval("document.project.lst_list" + i);
obj_list2 = eval("document.project.lst_list" + (i+1));
obj_count = eval("document.project.txt_count" + i);
obj_count2 = eval("document.project.txt_count" + (i+1));
obj_list.options[obj_list2.options.selectedIndex].selected = true;
obj_count.value = obj_count2.value;

}
for (i = numrows ;i > index;i--)
{
row_name = eval("row" + (i-1));
row_name2 = eval("row" + i);
row_name2.cells(1).innerHTML = row_name.cells(1).innerHTML
row_name2.cells(2).innerHTML = row_name.cells(2).innerHTML
}
}


function values()
{
numrows = document.all.project_table.rows.length;
str = "";
str += "count = " + document.project.count.value +"
";
for(i=1;i
{
obj_list = eval("document.project.lst_list"+i);
obj_count = eval("document.project.txt_count"+i);
str += obj_list.name + ": "+ obj_list.options[obj_list.selectedIndex].text+" "+obj_count.name+": "+obj_count.value+"
";
}
alert(str);
}



   <<Less

Re: ADD/DEL Row

Posted By:   Nitesh_Naveen  
Posted On:   Tuesday, March 25, 2003 07:37 AM

the insertRow and deleteRow functions work with the row index that is passed as the argument for these functions. You need to pass the index you need in your functions addrow() and deleter() and use this index instead of document.all.project_table.rows.length as in ur script
About | Sitemap | Contact