Focus in Textbox when the page is Loaded through Ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webhead
    New Member
    • Mar 2006
    • 56

    #31
    Originally posted by pbmods
    Because http actually *isn't* automatically assigning a value to response. I went back and looked at my AJAX frameworks, and it turns out that you have to manually do this.

    Yeah. *sheepish grin*

    So anyway, here's what initAjax *really* should look like (are we having fun yet?):
    Having fun... like the time our driver's ed instructor hit the car in front when we asked him to show us parallel parking with real cars instead of cones... 8-)

    Code:
    function initAjax(url, callback) {
    	var http = getHTTPObject(); 
    	http.open("GET", url, true);
    	http.onreadystatechange = function() {
    		if (http.readyState == 4) { callback(http); } 
    		};
    	http.send(null);
    	}
    w00t! It lives!

    But.... ::sobbing:: ... now there's no focus :-(
    Code:
    function initAjax(url, callback) {
    	var http = getHTTPObject(); 
    	http.open("GET", url, true);
    	http.onreadystatechange = function() {
    		if (http.readyState == 4) { callback(http); } 
    		};
    	http.send(null);
    	}
    
    function getTestpage() { 
    	url = "afunc.php";
    	initAjax(url, function (response) { 
    			document.getElementById(theOutput).innerHTML = response.responseText;
    			fldname.focus();
    		});
    	}

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #32
      Originally posted by webhead
      But.... ::sobbing:: ... now there's no focus :-(
      Hm. Your code is looking pretty good. The only thing I can think of is that fldname is not defined.

      Check your error console and see what's going on.

      Comment

      • webhead
        New Member
        • Mar 2006
        • 56

        #33
        Originally posted by pbmods
        Hm. Your code is looking pretty good. The only thing I can think of is that fldname is not defined.

        Check your error console and see what's going on.
        This works:
        Code:
        function getTestpage() { 
        	url = "afunc.php";
        	initAjax(url, function (response) { 
        			document.getElementById(theOutput).innerHTML = response.responseText;
        			document.getElementById('fldname').focus();
        		});
        	}
        Whew!

        Felt like wandering in the desert for 40 years just to go 20 miles, but worth the trip because things were learned. Thanks again for all your help. :-)

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #34
          Originally posted by webhead
          Felt like wandering in the desert for 40 years just to go 20 miles, but worth the trip because things were learned.
          On both sides (both parts :P).

          Originally posted by webhead
          Thanks again for all your help. :-)
          You are most welcome. Come back anytime!

          Comment

          Working...