I'm not very clued up with this Java script stuff, so excuse me for asking so much.
Thanks for your time.
If I'm correct, you are saying that I should put that in my selectsite.js ?
I know this is lots of code, but this is what it's currently looking like:
add_box.php
<script src='selectsite.js'></script>
<form name="location" method="post" action="">
Site:
<br>
<?
$sites = mysql_query("Select * from site",$con);
$siterows = mysql_num_rows($sites);
$n = 0;
?>
<select name="site" onchange="showsite(this.value)">
<option value="noselect" selected>Select Site</option>
<?
while($sit = mysql_fetch_array($sites, MYSQL_ASSOC))
{
$n++;
?>
<option value="<?php echo $sit['site_id'];?>"><?php echo $sit['site_name'];?></option>
<?
}
?>
</select>
<br>
Location Code:
<br>
<div id="txtHint"></div>
<input type="Submit" name="Add" value="Add">
</form>
It's this "txtHint" that need to POST with the rest of the Form.
selectsite.js
var xmlHttp
function showsite(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getsite.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
//Should I replace this line with:
//var txtHint = document.getElementById('txtHint').innerHTML;
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
getsite.php
<?php
$q=$_GET["q"];
include "config.php";
$sql="SELECT * FROM site WHERE site_id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$locations="SELECT * FROM location WHERE site = '". $row['site_id'] ."' AND box_number = 'vacant' order by rand() limit 1";
$results = mysql_query($locations);
while($rows = mysql_fetch_array($results))
{
echo "<font color='red'><strong>";
echo $rows['location_code']; //This is the value that goes to my form page
echo "</strong></font>";
/*
I have also tried this with no success:
<input type="hidden" name="location_code" value="<?php $rows['location_code'];?>">
*/
}
}
mysql_close($con);
?>
If I can get the value in the URL I'll be able to use it.