www.webdeveloper.com
Results 1 to 2 of 2

Thread: Ajax updating in IE but not in FF

  1. #1
    Join Date
    Jul 2004
    Location
    Cheshire, UK
    Posts
    11

    Ajax updating in IE but not in FF

    Hi guys,

    I have a problem with ajax working in IE 6 & 7 but not working in FF, and I was wondering if anyone could spot where I have gone wrong?

    What should happen is a user types a value into the inputamount1 field, if that value is >=2500, then a message is displayed to say you cannot continue, if not the message is not displayed.

    I type 2500 into the input field and the mesage appears, as I start deleteing the 2500 value from inputamount1, the message should disappear, and does so in IE but it does not in FF.

    This is my code:

    Code:
     <div id="capValue">
            <span></span>
    </div>
                         
    
     <form action="index.asp" method="post" id="form1" name="myCurrency">
    <div class="box amount">
        <label for="amount1">Amount</label><br />
        <input type="text" id="inputamount1" value="<%=Session("Amount1")%>" onkeyup='calCost1(this.value);'  />
        </div>
         <div class="box rate">
        <label for="rate1">Rate</label><br />
        <span id="rate1"><input type="text" id="inputrate1" value="<%=Session("Rate1")%>" /></span>
        </div>
         <div class="box cost">
        <label for="cost1">Cost</label><br />
        <span id="cost1"><input type="text" id="inputcost1" value="<%=Session("Cost1")%>" /></span><br class="clear" />
     </div>
    </form>
     
    <script type="text/javascript">
     var xmlHttp2
    function calCost1(Amount){
    	checkCapValue1();
    } 
    
    
    
    function GetXmlHttpObject2()
    { var xmlHttp2=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp2=new XMLHttpRequest();
    }
    catch (e)
    {
    // Internet Explorer
    try
    {
    xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    return xmlHttp2;
    }
    
    
    
    function checkCapValue1(){
    
    	var inputamount1 = parseInt(document.myCurrency.inputamount1.value, 10);
    
    
    	if(parseInt(inputamount1)>=2500){
    		document.myCurrency.submitcurrencies.disabled=true
    		document.myCurrency.submitcurrencies.style.backgroundImage="url(/images/mycurrency-nextstep-disabled.gif)";
    		xmlHttp8=GetXmlHttpObject8();
    		if (xmlHttp8==null){
    			alert ("Your browser does not support AJAX!");
    			return;
    		} 
    
    		var params = "&inputamount1=" + inputamount1;
    		var url="/includes/mycurrency-checkCapValue.asp";
    		xmlHttp8.onreadystatechange=stateChanged8;
    		xmlHttp8.open("POST",url,true);
    		xmlHttp8.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    		xmlHttp8.setRequestHeader("Content-length", params.length);
    		xmlHttp8.setRequestHeader("Connection", "close");
    		xmlHttp8.send(params);
    		return false;
    	
    	
    	}else{
    		document.myCurrency.submitcurrencies.disabled=false
    		document.myCurrency.submitcurrencies.style.backgroundImage="url(/images/mycurrency-nextstep.gif)";
    		xmlHttp9=GetXmlHttpObject9();
    		if (xmlHttp9==null){ 
    			alert ("Your browser does not support AJAX!");
    			return;
    		} 
    
    		var params = "&inputamount1=" + inputamount1 + "&empty=1";
    		var url="/includes/mycurrency-checkCapValue.asp";
    		xmlHttp9.onreadystatechange=stateChanged9;
    		xmlHttp9.open("POST",url,false);
    		xmlHttp9.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    		xmlHttp9.setRequestHeader("Content-length", params.length);
    		xmlHttp9.setRequestHeader("Connection", "close");
    		xmlHttp9.send(params);
    		return false;
    	}
    	
    }
    
    
    
    function stateChanged8(){ 
    	if (xmlHttp8.readyState == 4) {	
    		document.getElementById("capValue").innerHTML=xmlHttp8.responseText;
    		xmlHttp8=GetXmlHttpObject8();
    		
    	} 
    }
    
    
    
    function stateChanged9(){ 
    	if (xmlHttp9.readyState == 4) {	
    		document.getElementById("capValue").innerHTML=xmlHttp9.responseText;
    		xmlHttp9=GetXmlHttpObject9();
    		
    	} 
    }
    
     
     </script>

    mycurrency-checkCapValue.asp include file
    Code:
    <%
    	If Request.Form("empty") <> "1" Then
    	 	Response.write("<p>The amount exceeds of 2500.</p>")
    	Else
    		Response.write("")
    	End If
    %>

    In the Firebug console the posted variable 'empty' = 1 and the response is empty as it should be, but the message does not disappear from #capValue.

    Can anyone spot what I have done wrong?

    Thanks in advance for your help!

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    You really need to be testing
    Code:
    if (xmlHttp#.readyState == 4 && xmlHttp#.status == 200)
    Are you using more than one function and readystatechange function? You should be able to write AJAX so you can use the same function more than once, thereby drastically cutting down on your code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles