Displaying linked records of a category

IRHM73
03:17:12
Hi,

I wonder whether someone may be able to help me please.

I've been using the 'Displaying linked records of a category' example as a base to writing a more simplified version in that the data is only contained within one table rather than two.

I've put together the code below which creates the form and drop down menu which correctly shows the values I would expect.

<html>
<head>

<script type="text/javascript">
function ajaxFunction()
{

//document.writeln(val)
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}

function stateChanged(){
if(httpxml.readyState==4){

var myObject = eval('(' + httpxml.responseText + ')');


//var myObject = httpxml.responseText;
//document.getElementById("display").innerHTML=myObject;


var msg=myObject.value[0].message;
if(msg.length > 0){document.getElementById("msg").innerHTML=msg;}
else{document.getElementById("msg").style.display='none';}

var str="<table width='50%' bgcolor='#ffffff' align=center><tr><th>ID</th><th>Name</th></tr>";
var color="#f1f1f1";
for(i=0;i<myObject.data.length;i++)
{
if((i%2)==0){color="#ffffff";}
else{color="#f1f1f1";}
str = str + "<tr bgcolor="+color+"><td>" + myObject.data[i].findid + " </td><td>"+ myObject.data[i].dateoftrip + "</a></td></tr>"

}


str = str + "</table>" ;


document.getElementById("display").innerHTML=str;
}
}

var url="getrecords.php";
var findid=document.myForm.findid.value;
url=url+"?findid="+findid;

url=url+"&kid="+Math.random();
//alert(url)
httpxml.onreadystatechange=stateChanged;
httpxml.open("GET",url,true);
httpxml.send(null);
// document.getElementById("display").innerHTML="Please Wait....";
document.getElementById("msg").style.background='#f1f1f1';
document.getElementById("msg").innerHTML="Please Wait ... ";
document.getElementById("msg").style.display='inline';
}

</script>

<style type="text/css">
<!--
.style1 {
font-family: Calibri;
font-size: 14px;
}
-->
</style>
</head>
<body>

<form action="getrecords.php" method="get" name="frm1">

<table width="148" border="0">

<tr>
<td width="152"><p class="style1">Select a date from below</p>
<div align="center">
<?php
include("db.php");

$query="SELECT * FROM finds group by dateoftrip";
$result=mysql_query($query);
echo mysql_error();
echo "<select name=findid onChange=\"ajaxFunction()\"><option value=0>Show All</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[findid]>$nt[dateoftrip]</option>";
}

echo "</select>";
?>
</div></td>
</tr>
</table>
</form>
<div id="my_div"></div>
</body>
</html>


The problem I'm having is retrieving the information.

This is the code I've been using to try and get the records from my database table:

<?php

require "db.php"; //Your database details here
//////////////////////////// Main Code sarts ///////////////
@$findid=$_GET['findid'];
//$findid=1;

if(!is_numeric($findid)){
echo "Data Error ";
exit;
}

$message="";

if($findid>0){
$q=mysql_query("select findid, dateoftrip from finds where findid=$findid");
}else{
$q=mysql_query("select findid, dateoftrip from finds");
$findid=0;
}
@$message .= mysql_error();

$str= "{ \"data\" : [ ";

while($nt=mysql_fetch_array($q)){
$str=$str."{\"findid\" : \"$nt[findid]\", \"dateoftrip\" : \"$nt[dateoftrip]\"},";
//$str=$str."{"myclass" : "$nt[class]"},";

}
$str=substr($str,0,(strLen($str)-1));
$message=$message. " Records displayed";
$str=$str."],\"value\" : [{\"findid\" : $findid,\"message\" : \"$message\"}]}";
//echo json_encode($str);

echo $str;
?>


When I run this with the drop down menu I get the following message:

[quote]document.myForm.findid' is null or not an object Line: 73[/quote] which is this line in my form [quote]var findid=document.myForm.findid.value;[/quote].

I'm really not sure where I'm going wrong. I've been over the code quite a few times, but I just can't find the answer.

I just wondered whether someone could perhaps take a look at this please and let me know where I'm going wrong.

Many thanks and regards

Chris

PROBLEM NOW RESOLVED - CLOSED
Please Login to post your reply or start a new topic