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 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    How to bypass one AJAX function if there's no onchange

    I have a dynamic form consisting mostly of drop down menus that dynamically populate the next drop down via an onchange AJAX function; however, one of the fields is a check box, and I'm stumped as to how to proceed to the next function if there's no onchange. If the check box is checked, the price will be different.

    Code:
    // checkbox
    function getPreference(var1Id,var2Id,var3Id,var4Id) {		
    	var strURL="findPreference.php?var1="+var1Id+"&var2="+var2Id+"&var3="+var3Id+"&var4="+var4Id;
    	var req = getXMLHTTP();
    	
    	if (req) {			
    		req.onreadystatechange = function() {
    			if (req.readyState == 4) {
    				// only if "OK"
    				if (req.status == 200) {
    					document.getElementById('prefdiv').innerHTML=req.responseText;						
    				} else {
    					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    				}
    			}				
    		}			
    		req.open("GET", strURL, true);
    		req.send(null);
    		}				
    	}
    
    function getPrice(var1Id,var2Id,var3Id,var4Id,var5Id) {		
    	var strURL="findPrice.php?var1="+var1Id+"&var2="+var2Id+"&var3="+var3Id+"&var4="+var4Id+"&var5="+var5Id;
    	var req = getXMLHTTP();
    	
    	if (req) {			
    		req.onreadystatechange = function() {
    			if (req.readyState == 4) {
    				// only if "OK"
    				if (req.status == 200) {
    					document.getElementById('pricediv').innerHTML=req.responseText;						
    				} else {
    					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    				}
    			}				
    		}			
    		req.open("GET", strURL, true);
    		req.send(null);
    		}				
    	}
    The checkbox
    Code:
    <p><input type="checkbox" id="var5" name="var5" value="true" onchange="getPrice(<?=$var1?>,<?=$var2?>,<?=$var3?>,<?=$var4?>,this.value)"/> If checked price will increase</p>
    Any help will be greatly appreciated as I'm not finding any solutions on the web.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Nevermind. I figured it out :P


  •  

    Posting Permissions

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