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.