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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts

    Open at top problem

    Hello All,

    I have a page that loads in the middle of my page because I added a php search bar that uses jquery and javascript. How can I force the page to open at the top?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Change your jQuery code? Something in it is moving the focus to the search bar. Find what is doing that and get rid of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    jchrisphonte (02-27-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    Thank you for the tip Pendant,

    sadly Im not familiar with javascript or jquery- I found this code online.... Would you mind pointing out the line to remove if I post the code below?

    Code:
    search_id= '';
      function handleHttpResponse() {
    		if (http.readyState== 4) {
    			if (search_id != '') {
    				document.getElementById(search_id).innerHTML= http.responseText;
    			}
    		}
    	}
      function getHTTPObject() {
    		var xmlhttp;
    		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    			try {
    				xmlhttp= new XMLHttpRequest();
    			} catch (e) {
    				xmlhttp= false;
    			}
    		}
    		return xmlhttp;
    	}
    	var http= getHTTPObject();
    
      function getScriptPage(div_id,terms_id,get_count,get_p) {
        search_id= div_id;
         zearch= document.getElementById(terms_id).value;
        http.open("GET", "search.php?terms=" + escape(zearch)+"&count="+get_count+"&page="+get_p, true);
       http.onreadystatechange= handleHttpResponse;
      http.send(null);
    	}
    another page use by search bar:

    Code:
    function GetXmlHttpObject(handler)
    {
      var objXMLHttp=null
      if (window.XMLHttpRequest)
      {
          objXMLHttp=new XMLHttpRequest()
      }
      else if (window.ActiveXObject)
      {
          objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
      }
      return objXMLHttp
    }
    
    function stateChanged()
    {
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
      {
              // show_results will be filled with new page
              document.getElementById("show_results").innerHTML= xmlHttp.responseText;
    		  document.getElementById("show_results").scrollIntoView();
      }
    }
    
    function htmlData(url, terms, pag)
    {
      if (url.length==0)
      {
          document.getElementById("show_results").innerHTML= "";
          return;
      }
    
      xmlHttp= GetXmlHttpObject();
    
      if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
    
      url=url+"?"+terms+"&"+pag;
      url=url+"&sid="+Math.random();
      xmlHttp.onreadystatechange= stateChanged;
      xmlHttp.open("GET",url,true) ;
      xmlHttp.send(null);
    }
    Last edited by jchrisphonte; 02-27-2012 at 02:25 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    It's this line:
    Code:
          document.getElementById("show_results").scrollIntoView();
    Try commenting it out ( put // in front of the line ) and see if that does it. It should.

    I don't see anything in the first block of code that would do this.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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