Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Search on page

  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search on page

    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:

    Code:
    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;
    		  }
    		  }

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    double click the warning icon to see what the error is.

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it says "document.search.string is null or not an object"

  • #4
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    by the way this is the bit that i use to display the input box on the page:
    Code:
    <input type="button" value="Find" onclick="return findInPage(document.search.string.value);">
    that's what the error message is about

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what's your form look like?

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.search.string.value
    You need to reference the value of your form object.

    e.g.
    document.myForm.myTextfield.value

    or
    this.form.myTextfield.value


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •