onblur failing / not initiating

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • empiresolutions
    New Member
    • Apr 2006
    • 162

    onblur failing / not initiating

    i am using the following AJAX request method. Most of you probably use this script allready as it seems to be everywhere online. I use it often with out issue... until now.

    What I'm finding is that if the click used to initiate the onblur() used like
    Code:
    <input type="text" id="qty" name="qty" value="" onblur="makeRequest('ajax_insert.php?field_name=qty&field_value=',this.value);">
    is on either a link or from submit button, the onblur() never gets called. In my code, the onblur() has to work if the user goes strait for the submit button before clicking anywhere else.

    Any ideas on how to get it to call onblur() and refresh in a one click process? Thanks much for the help.

    My AJAX code
    Code:
    function makeRequest(url, parameters) { 
    
    	http_request = false;
    
    	if (window.ActiveXObject) { // IE
    
    		try {
    
    			http_request = new ActiveXObject("Msxml2.XMLHTTP");
    
    		} catch (e) {
    
    			try {
    
    				http_request = new ActiveXObject("Microsoft.XMLHTTP");
    
    			} catch (e) {}
    
    		}
    
    	} else if (window.XMLHttpRequest) { // Mozilla, Safari, Sometimes IE7...
    
    		http_request = new XMLHttpRequest();
    
    		if (http_request.overrideMimeType) {
    
    			// set type accordingly to anticipated content type
    			http_request.overrideMimeType('text/xml');
    			// http_request.overrideMimeType('text/html');
    
    		}else{ alert('Did not create *http_request.overrideMimeType*'); return false; }
    
    	} 
    
    	if (!http_request) {
    
    		alert('Cannot create XMLHTTP instance');
    		return false;
    
    	}
    
    	http_request.onreadystatechange = alertContents;
    
    	// FOR POST VARS
    	//http_request.open('POST', url, true);
    	//http_request.send(parameters);
    
    	// FOR GET VARS
    	//alert(url + parameters);
    	http_request.open('GET', url + parameters, true);
    	http_request.send(null);
    	
    }
    
    function alertContents() {
    	if (http_request.readyState == 4) {
    	 if (http_request.status == 200) {
    		//alert(http_request.responseText);
    		result = http_request.responseText;
    		document.getElementById('myspan').innerHTML = result;
    	 } else {
    		alert('There was a problem with the request.');
    	 }
    	}
    }
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Why not validate when the submit button is clicked that no changes have been made?

    Comment

    • empiresolutions
      New Member
      • Apr 2006
      • 162

      #3
      Originally posted by acoder
      Why not validate when the submit button is clicked that no changes have been made?
      hmmm... can you give an example? My form has three text fields.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Your issue was with the submit button being clicked without clicking anywhere else.

        Call the function that you'd call onblur onclick or even onsubmit instead.

        Comment

        Working...