Javascript function error : URGENT HELP

Hi,

I have a problem with javascript functions. I really need your help asap.

I have two functions. printArray() & nextRecords().

I'm passing parameters between these two functions.

printArray() is displaying first 5 elements of Array . Then this function has 'Next' button . If I click 'Next' button , it calls nextRecord() & it displays next 5 records. Again if I click 'Next' button It displays next 5 records & so on.

I'm able to display next 5 records only if i hit 'Next' button first time. If I click it again it is saying 'object not found' because it is generating new HTML page & It is not able to find nextRecord function.

In short I want to dispaly contents of Array pagewise. How can I display it?

Please I'm in badly need.

Thanks in advance.

-Priya

[879 byte] By [Priyam] at [2007-9-26 1:31:02]
# 1
Simplest soln is when you are writing new page try to write the array to a hidden variable .
sribk at 2007-6-29 1:29:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

My functions are like this. Could you please tell me where should I put this array in hidden var?

function printArray(mStartIndex,mEndIndex,mDataArray)

{

pStartIndex = mStartIndex;

pEndIndex = mEndIndex;

pDataArray = mDataArray;

document.writeln('<HTML>');

document.writeln('<TABLE BORDER = 1>');

for( var i = pStartIndex; (i < pEndIndex) && (i < pDataArray.length); i++)

{

document.writeln('<TR>');

document.writeln('<TD>');

document.writeln(pDataArray);

document.writeln('</TD>');

document.writeln('</TR>');

pStartIndex = i;

}

document.writeln('</TABLE>');

document.writeln('</HTML>');

if(pEndIndex >= pDataArray.length )

{

document.write("Next");

}

else

{

document.write("<input type = 'button' value = 'Next' onClick = 'nextRecords(" + pStartIndex + "," + pEndIndex +")'>");

}

if(pStartIndex <= 0)

{

document.write("Previous");

}

else

{

document.write('<input type = button value = Previous onClick = previousRecords()>');

}

}

function nextRecords(startIndex,endIndex)

{

if (startIndex == 0)

{

}

if ((startIndex > 0) && (startIndex < xArray.length))

{

startIndex = endIndex;

endIndex = startIndex + pSize;

printArray(startIndex,endIndex,xArray);

}

}

Priyam at 2007-6-29 1:29:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

// your array variable here

arra

// first page

printArray()

nextRecords(){

// Note using document.write statements

// write your nextRecords function here

// get hidden arra value here

// end your function here

//for loop

document.write( ''' bla ..bla...");

document.write( ''' bla ..bla...");

document.write( ''' bla ..bla...");

//for loop ends here

// write form tag here

document.write( "<input type="hidden" value="+arra+">");

// your next button ..here

// end form tag here

}

hope you got it..

sribk at 2007-6-29 1:29:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi ,

I modified my function but I'm not able to get values in nextRecords function.

I tried to figure it out but couldn't.

I appreciate your help.

function printArray(mStartIndex,mEndIndex,mDataArray)

{

var pStartIndex = mStartIndex;

var pEndIndex = mEndIndex;

var pDataArray = new Array();

pDataArray = mDataArray;

document.writeln('<HTML>');

document.writeln('<HEAD>');

if(flag == true)

{

document.writeln('<script language = javascript>');

document.writeln('function nextRecords(nStartIndex, nEndIndex)');

document.writeln('{');

document.writeln("alert(" + "'Working'" + ");");

document.writeln('var dArray = new Array();');

document.writeln('dArray = document.frm.hiddenDataArray.value;');

document.writeln('document.writeln(dArray.length);');

document.writeln('for( var i = 0; (i < 5) && (i < 14); i++)');

document.writeln('{');

document.writeln('document.writeln("<TR>");');

document.writeln('document.writeln("<TD>");');

document.writeln('document.writeln(dArray);');

document.writeln('document.writeln("</TD>");');

document.writeln('document.writeln("</TR>");');

//document.writeln('nStartIndex = i;');

document.writeln('}');

document.writeln('}');

document.writeln("<" + "/" + "script>");

document.writeln("<" + "/" + "head>");

}

document.writeln('<BODY>');

document.writeln('<FORM NAME = frm>');

document.writeln('<TABLE BORDER = 1>');

for( var i = pStartIndex; (i < pEndIndex) && (i < pDataArray.length); i++)

{

document.writeln('<TR>');

document.writeln('<TD>');

document.writeln(pDataArray);

document.writeln('</TD>');

document.writeln('</TR>');

pStartIndex = i;

}

document.writeln('</TABLE>');

document.writeln('<INPUT TYPE = HIDDEN NAME = hiddenDataArray VALUE = " +pDataArray +" >');

if(eIndex >= xArray.length )

{

document.write("Next");

}

else

{

document.write("<input type = 'button' value = 'Next' onClick = nextRecords(" + pStartIndex + "," + pEndIndex +")>");

}

document.writeln('</FORM>');

document.writeln('</BODY>');

document.writeln('</HTML>');

}

Priyam at 2007-6-29 1:29:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...