ok here is my problem
i created the JS to insert rows in an html doc, this works perfectly but if i was to refresh the page or leave it and return to it L8 the rows have diappeared here is the code i would appreciate it if any1 could give me some suggestions
the coding is a bit of a headache , even though i created i, but please help me!
function addLine()
{
var Documents = new Array(6)
Documents[0]="....";
Documents[1]=" Invoice";
Documents[2]=" Bill";
Documents[3]=" List";
Documents[4]="Policy";
Documents[5]="Other";
var tbody = document.getElementById("table1").getElementsByTagName("tbody")[0];
var Values = document.getElementById('Value1');
var ValuesInt = (document.getElementById("Value1").value -1)+ 2; //gets the current value from Value1
Values.value = ValuesInt; //overides the current values
var nums = ValuesInt; //for the documents
var TRIdName = "Create"+ ValuesInt +"TR";
var row = document.createElement("TR"); //creation of the tr
row.setAttribute("id",TRIdName); //setting the attribute id = "create 1 Tr helps to id for the deletion"
var Cells = new Array(3) //creation of the td
var Selection = new Array(3) //creation of the selection
var Options = new Array(3) //creation of the option
var Inputs = new Array(3) //creation of the Input
var XSLValues = new Array(3)
// the flow is cells -> selection -> options -> inputs -> xslvalues, insert in the documents
if(ValuesInt <=8)
{ for (var a=0; a < Cells.length; a++)
{
Cells[a]= document.createElement("TD");
Selection[a]= document.createElement("select");
Selection[a].className = 'Text';
if(a==0) //if statement to set the selection attribute for addDocs
{
Selection[0].setAttribute("id","addDocuments"+nums);
Selection[0].onchange = function()
{
DropDownMenuList('addDocuments'+nums);
}
for (var b=0; b < Documents.length; b++)
{
Options[0]=document.createElement("option");
theText=document.createTextNode(Documents[b]);
Options[0].appendChild(theText);
Selection[0].appendChild(Options[0]);
}
}
else
{
if(a==1) //if statement to set the selection attribute for originals if count is equal to 1 else go and do Duplicates
{
Selection[1].setAttribute("id","Originals"+nums);
Selection[1].onchange = function()
{
DropDownMenuList('Originals'+nums);
}
}
else
{
Selection[2].setAttribute("id","Duplicates"+nums);
Selection[2].onchange = function()
{
DropDownMenuList('Duplicates'+nums);
}
}
for (var b=0; b < 10; b++)
{
Options[a]=document.createElement("option");
if(b==0)
{
theText=document.createTextNode("...");
}
else { theText=document.createTextNode(b); }
Options[a].appendChild(theText);
Selection[a].appendChild(Options[a]);
}
}
}
var ListOfNames = new Array(3);
ListOfNames[0]="addDocuments"
ListOfNames[1]="Originals"
ListOfNames[2]="Duplicates"
alert("Adding Documents, Copies and Duplicates Row"+nums);
for (var i=0; i<ListOfNames.length ;i++)
{
Inputs[i]= document.createElement("input");
Inputs[i].setAttribute("id","Input"+ListOfNames[i]+nums);
Inputs[i].setAttribute("name",ListOfNames[i]+nums);
Inputs[i].setAttribute("type","text");
Inputs[i].className = 'hide';
XSLValues[i]= document.createElement("xsl");
XSLValues[i].setAttribute("name","value");
XSLValues[i].setAttribute("value-of select","document/fields/field/"+ListOfNames[i]+nums);
}
for (var c=0; c < Cells.length ; c++)
{
Cells[c].appendChild(Selection[c]);
Cells[c].appendChild(Inputs[c])
Cells[c].appendChild(XSLValues[c])
row.appendChild(Cells[c]);
}
tbody.appendChild(row);
}
else alert("no more rows to be added");
}
|
|
July 10th, 2006 10:20 PM
# 2
|
Re: trouble with my javascript sort of
Inserting rows like this does not actually change the HTML document on the server only the current browser DOM which is why the changes are removed by a refresh or coming back later, you reload the original document.
If you want the changes to be permantent then you need to create a way for the changes to be submitted to some CGI script and for that script to store the changes and you will need to alter the page so that when it is retrieved from the server more CGI runs to pick up any changes and alter the HTML code appropriately.
There are many CGI scripting languages you could use Perl, PHP Python, asp, Ruby to name a few.
__________________
A method worth implementing is worth invoking :D