I have code to develop result page links (like a search engine) for some
results being passed from a database where I've no server-sdide acces -
thus JS.
The code is below and works fine except the function in the onClick
event of the link being written on screen fails indicating 'theForm' as
being passed through is 'not defined'. The form is being passed as
"document.resul tAdd" and can be checked as arriving in my function.
So what am I doing wrong?
FWIW, if I place the alert in the calling code (see code example) I see
passed object in the string as [object] - is that what I should expect?
Regards
Mark
############### ############### ############### #######
//curOffset - offset number in total items (parsed from GET method URL)
//numPerPage - (number) number of records per result page
//totalItems - (number) total items in records set (at n per page)
//numLinks - (number) number of links to create (odd number)
//linkName,thePag e,task,theForm - vars passed through for string being
written
function
makeNavLinks(cu rOffset,numPerP age,totalItems, numLinks,linkNa me,thePage,t
ask,theForm){
var numPages= 1 + Math.floor(tota lItems/numPerPage);
var strLinks = '',theOffset = '',newOffset = '',newPage = '',start =
0, i = 0;
var linkStubA = 'Jump to page: - ';
var linkStubB = '<a href="#" onClick="alert( theForm);goWher e(\'' +
linkName + '\',\'';
var linkStubC = '\',\'' + task + '\',' + theForm + '); return
false;">';
var linkStubD = '</a> ' ;
if (numPages == 1){
strLinks = linkStubA + numPages;
return strLinks;
} else {
var curPage = ((curOffset/numPerPage) + 1);
var halfLink = Math.floor(numL inks/2);
if (numLinks > numPages) {
numLinks = numPages
}
if ((curPage-halfLink) < 1) {
i = 1;
} else if ((curPage + halfLink) > numPages) {
i= (numPages-numLinks);
} else {
i = (curPage - halfLink);
}
strLinks = linkStubA;
for ( var k = i ; k < (i + numLinks); k ++){
if (((k-1)* numPerPage)== curOffset) {
strLinks += k + ' ';
} else {
thisOffset = ((k - 1) * numPerPage).toS tring();
newOffset = '&offset=' + thisOffset;
newPage = thePage.replace (/&offset=\d+/,newOffset);
strLinks += linkStubB + newPage + linkStubC + k + linkStubD
+'\n\n';
}
}
return strLinks;
}
}
////////////////////////
...called by... (%totalItems% is a server-side macro)
var x =
makeNavLinks(pa geOffset,myResu ltsPerPage,%tot alitems%,9,'PAG ELIST',thisP
age,'ADD',docum ent.resultAdd);
//alert(x)
document.write( x);
############### ############### ############### ####
results being passed from a database where I've no server-sdide acces -
thus JS.
The code is below and works fine except the function in the onClick
event of the link being written on screen fails indicating 'theForm' as
being passed through is 'not defined'. The form is being passed as
"document.resul tAdd" and can be checked as arriving in my function.
So what am I doing wrong?
FWIW, if I place the alert in the calling code (see code example) I see
passed object in the string as [object] - is that what I should expect?
Regards
Mark
############### ############### ############### #######
//curOffset - offset number in total items (parsed from GET method URL)
//numPerPage - (number) number of records per result page
//totalItems - (number) total items in records set (at n per page)
//numLinks - (number) number of links to create (odd number)
//linkName,thePag e,task,theForm - vars passed through for string being
written
function
makeNavLinks(cu rOffset,numPerP age,totalItems, numLinks,linkNa me,thePage,t
ask,theForm){
var numPages= 1 + Math.floor(tota lItems/numPerPage);
var strLinks = '',theOffset = '',newOffset = '',newPage = '',start =
0, i = 0;
var linkStubA = 'Jump to page: - ';
var linkStubB = '<a href="#" onClick="alert( theForm);goWher e(\'' +
linkName + '\',\'';
var linkStubC = '\',\'' + task + '\',' + theForm + '); return
false;">';
var linkStubD = '</a> ' ;
if (numPages == 1){
strLinks = linkStubA + numPages;
return strLinks;
} else {
var curPage = ((curOffset/numPerPage) + 1);
var halfLink = Math.floor(numL inks/2);
if (numLinks > numPages) {
numLinks = numPages
}
if ((curPage-halfLink) < 1) {
i = 1;
} else if ((curPage + halfLink) > numPages) {
i= (numPages-numLinks);
} else {
i = (curPage - halfLink);
}
strLinks = linkStubA;
for ( var k = i ; k < (i + numLinks); k ++){
if (((k-1)* numPerPage)== curOffset) {
strLinks += k + ' ';
} else {
thisOffset = ((k - 1) * numPerPage).toS tring();
newOffset = '&offset=' + thisOffset;
newPage = thePage.replace (/&offset=\d+/,newOffset);
strLinks += linkStubB + newPage + linkStubC + k + linkStubD
+'\n\n';
}
}
return strLinks;
}
}
////////////////////////
...called by... (%totalItems% is a server-side macro)
var x =
makeNavLinks(pa geOffset,myResu ltsPerPage,%tot alitems%,9,'PAG ELIST',thisP
age,'ADD',docum ent.resultAdd);
//alert(x)
document.write( x);
############### ############### ############### ####
Comment