...

View Full Version : Search on page



dav_asp
04-13-2007, 11:11 AM
Hi,
i've got an asp page that displays a lot of records from a DB. I added some javascript to get the user to input a number that should be displayed on the page. It's meant to work like the find option in microsoft programs.

Everytime the button submitting the number is pressed, a warning message is displayed in the bottom-left corner of the browser that says "Error on page".

here's my coding:


var numtimes = 0;

function findinpage(str) {

if (str == "") return false;

if (document.layers) {
if (!window.find(str)) {
while(window.find(str, false, true)) n++;
}
else numtimes++;

if (numtimes == 0) alert("The invoice number \""+ str +"\" was not found on this page.");
}

if (document.all) {
var txt = window.document.body.createTextRange();
var found = txt.findText(str);

for (var i = 0; i <= numtimes && found != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}

if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
numtimes++;
}

else {
if (numtimes > 0) {
numtimes = 0;
findinpage(str);
}

else alert("The invoice number \""+ str +"\" was not found on this page.");
}
return false;
}
}

mehere
04-13-2007, 03:13 PM
double click the warning icon to see what the error is.

dav_asp
04-13-2007, 03:52 PM
it says "document.search.string is null or not an object"

dav_asp
04-13-2007, 03:59 PM
by the way this is the bit that i use to display the input box on the page:

<input type="button" value="Find" onclick="return findInPage(document.search.string.value);">

that's what the error message is about

mehere
04-13-2007, 04:42 PM
what's your form look like?

degsy
04-18-2007, 02:06 PM
document.search.string.valueYou need to reference the value of your form object.

e.g.
document.myForm.myTextfield.value

or
this.form.myTextfield.value



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum