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 12 of 12
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    onreadystatechanged giving probs in FF

    Code:
    // send query to jsp for processing (with name of selected ingredient)
        url = "get.jsp?selected_sub="
        url += document.getElementById("sub_selectbox" + 
    								 qty_index).getElementsByTagName("option")[sub_index].text;
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = handleResponse;
        xmlHttp.send(null);  
      
        // handle processed output  
        function handleResponse(){
          if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            // store processed response text
            var getVal = xmlHttp.responseText;
    	   if (((a.getElementsByTagName("input")[0].value)*1)>1) {
    	     getVal *= a.getElementsByTagName("input")[0].value;
    	   }
            // display the value to user with multiplier to account for servings change(s)
    	    if (multiplier!=0) {
              document.getElementById("qty" + qty_index).innerHTML=(getVal*multiplier);
    	    }
    	    else {
    		   document.getElementById("qty" + qty_index).innerHTML=(getVal);
    	    }
          }
    I am trying to get values from a JSP and display to USER, JSP gets values from a database. First displays 3 choices to user, user selects one and the JSP Gives back a table and there are few select boxes in the data returned and the user selects whatever option he wants in this table. This all works when I have two choices in the FIRST select box I talked about even in FF. But when I added a 3rd option (and the data associated with it returns) the user tires to select an option, Firebug tells me the handleResponse is not defined. This code is for the the select boxes from my JSP. Again all of this works in IE. Ill post screens cuz I don't have any way to put it online.

    Initial selection:




    then the data with select boxes comes in and displayed:



    then i select the other option in the select box (first one in the table) and error happens >< :


  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Try putting open after readystatechange
    Code:
        
        xmlHttp.onreadystatechange = handleResponse;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    You will need to create a new instance of the XMLHttpRequest object for each request for IE, if you are not already.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    nope still gives me that same error in firefox

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Is handleResponse available to line 196?

    With the requests being on different lines in firebug I assume you have more than one HttpRequest function.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    more than 1 httpRequest function meaning the onreadystatechange ? cuz I have em in different functions and each one sends a new query...do i have to close when i use xmlHttp.open or something?

    i said in my first post, the whole thing works in IE and it works if I have TWO choices in the first select box (see 1st screen shot) so I have no idea why this won't work!!

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Maybe, for testing, a check just before the request
    Code:
     if (typeof xmlhttp != 'object') { alert('xmlHttp is not an object'); }
     if (typeof handleResponse != 'function') { alert('handleResponse is not a function');  }
    
       xmlHttp.open("GET", url, true);
       xmlHttp.onreadystatechange = handleResponse;
       xmlHttp.send(null);
    You could also check for errors in the response, but they should be visible in firebug
    Code:
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
              ........
        } else {
             alert(xmlHttp.status + ' -- ' + xmlHttp.statusText);
        }
     }
    Last edited by rwedge; 09-12-2007 at 09:22 AM.

  • Users who have thanked rwedge for this post:

    zenithwolf (09-12-2007)

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    did those checks and for some odd reason Firefox just CANNOT find that function, no matter what its named. It doesnt even enter the function just says its not even a function! still works in IE tho...

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    i got it working...I just removed the handle response as a different function and just put onreadystatechange as a function directly and now it works...

    Code:
    //if (typeof xmlHttp != 'object') { alert('xmlHttp is not an object'); }
        //if (typeof handleResponse != 'function') { alert('handleResponse is not a function');  }
    	
        // send query to jsp for processing (with name of selected ingredient)
        url = "get.jsp?selected_sub="
        url += document.getElementById("sub_selectbox" + qty_index).getElementsByTagName("option")[sub_index].text;
        xmlHttp.open("POST", url, true)
        xmlHttp.onreadystatechange = function() {
    	  
    	  // handle any errors that arise
          var status = "N/A";
          var statusText = "N/A";
          try{ status = xmlHttp.status;}catch(e){}
          try{ statusText = xmlHttp.statusText}catch(e){}
    	  //handle processed output
    	  if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            // store processed response text
            var getVal = xmlHttp.responseText;
    	   if (((a.getElementsByTagName("input")[0].value)*1)>1) {
    	     getVal *= a.getElementsByTagName("input")[0].value;
    	   }
            // display the value to user with multiplier to account for servings change(s)
    	    if (multiplier!=0) {
              document.getElementById("qty" + qty_index).innerHTML=(getVal*multiplier);
    	    }
    	    else {
    		   document.getElementById("qty" + qty_index).innerHTML=(getVal);
    	    }
          }
        };
        xmlHttp.send(null);

  • #9
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    The problem was you need to define the function before you set its value since it is not global.

    It is like you eating a sandwhich before you actually make it. You will not eat anything because it is not there yet.

    Eirc
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    The problem was you need to define the function before you set its value since it is not global.

    It is like you eating a sandwhich before you actually make it. You will not eat anything because it is not there yet.

    Eirc
    True, but it works everywhere else and it occurs for a certain amount of entries only...

  • #11
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sometimes odd coding will work but inconsistently. Just cause something worked, does not mean it is correct. In other cases, it will crap out.

  • #12
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    hmm odd coding eh? I just adopted what I saw in a tutorial


  •  

    Posting Permissions

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