I keep getting an object expected error at the start of my <body>

I've set a form to value="Accountants" and <body onload="showindex()"> in an attempt to automatically submit this value to a js file whenever the page loads. My aim is to have dozens of html pages all using the same js file to return information based on the contents of that value.

Code is below, Any help much appreciated.

index.html

<head>   
<script src="AccountantsLoad.js"></script>
</head>
<body onload="showindex();"> 
  <FORM name="myForm">
    <INPUT type="text" readonly name="class" value="Accountants" size="15">
  </FORM>	  
</body>

AccountantsLoad.js file

function showindex()
{ 
var xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
xmlHttp.onreadystatechange=function(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtindex").innerHTML=xmlHttp.responseText;
 } 
};
var var1 = document.myForm.class.value;
var url = "AccountantsReturn.php";
url+="?q="+var1;
url+="&sid="+Math.random();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function GetXmlHttpObject(handler)
{
var xmlHttp=null;
	if (window.XMLHttpRequest)
	{
		//code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//code for IE6, IE5
		try
		{
		xmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {alert (e.description);}
	}
	return xmlHttp;
}

AccountantsReturn.php

<?php
include("../blahblah.php");
$q=$_GET["q"];

$con=@mysql_connect("localhost",$username,$password);
$rs=@mysql_select_db($database) or die("Unable to select database");

$endDateNull = 'This is a Continuous promotion';

$sql5 ="SELECT Name
FROM Company
WHERE Classification = '".$q."' ORDER BY Name ASC";

$result5 = mysql_query($sql5);


while ($newrow5 = mysql_fetch_array($result5))
{
}
mysql_close($con);
?>

I'm probably not submitting the form value correctly or the js file 'url' variable isn't being put together right.

Cheers again,

Tom.

Recommended Answers

All 5 Replies

just noticed by previewing the post that i called the value 'class' which i think is a pre-defined operator or something (excuse my ignorance). Anyway i've changed that and i'm not getting the object expected error anymorw but neither is anything loading.

Still need help as i definitely think i've messed up the 'url' variable as 'q' doesnt seem to be getting over to the php file.

thanks,

Tom.

Member Avatar for rajarajan2017
<script type="text/javascript" src="external.js"></script>
<script type="text/javascript" src="external.js"></script>

Nope that didn't do it. Nothin loading.

Can you verify that you are getting the correct HttpRequest object? If you are using IE a possible problem is this misspelling of your request object as:

xmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");

should be

xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

I would then suggest (if you haven't already) stepping through the javascript (using alerts or console.log() if you are using IE8) to ensure you are getting your values correctly. You may need to get the input element via document.getElementById as IE sometimes doesn't select the form element correctly off of the DOM (don't know why was told this at work and have run into the error myself). And finally (in case you haven't already) use print statements in the php to ensure you are at least getting to the page in question.

thanks for the help with that. I also set 'q'=1 in the PHP which obviously wasn't returning any results.
That's what i get for copying and manipulating code from elsewhere in my site and not changing the variables.

Cheers,

Tom.

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.