Hi and I'm no noob 2 ajax and have used it many times before. But for some reason this script doesn't want to work on any browser except Internet Explorer. Can anybody see what I have done wrong in this code as I have searched and searched for hours and only found things that don't work. I have another script that works that is almost identical to this one so I'm not sure what could possibly be wrong.

<script language="javascript" type="text/javascript">
function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}
</script><script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function new_chatroom(var1){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
    // Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			returnObjById("resultsfield").innerHTML = ajaxRequest.responseText;
		}
	}
    // Create a function that will receive data sent from the server
    ajaxRequest.open("GET", "'.$danibot['scriptpath'].'/extensions/danibot/results.php?q="+returnObjById("q").value, true);
	ajaxRequest.send(null); 
    }
//-->
</script><script language="javascript" type="text/javascript">
//http://www.cs.tut.fi/~jkorpela/forms/enter.html
function noenter() {
  if (window.event && window.event.keyCode == 13) {
    getresults();
    }
  return !(window.event && window.event.keyCode == 13); }

</script>

Please help.

Found the problem.
I forgot to add id="q" in the input field. And this was thanks to the discover of the Opera debugger which can be enabled through the preferences list. In my opinion Opera has the best debugger in the World Web as it tells you the near exact error line and a few related lines.
*Solved*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.