Hi,
This is an addition to the code below, as at this point it works perfectly, but have added an extra option for the user to search for hotels in our database.
Up until today the user could simply start typing in the search box and the search will display hotels according to the region they are typing, as that is what is asked of them.
But what we have added in now is 2 radio buttons that give the user an option to either search by resort or hotel, and what I need help with the code below is how to check which radio button has been chosen and then how to tailor the search.
<form name="myForm"
<input type="radio" name="choice" value="resort" checked> Resort <input type="radio" name="choice" value="hotel"> Hotel
<input type="text" onkeyup="ajaxFunction(this.value);" name="username" class="text"/>
</form>
<script type="text/javascript">
function ajaxFunction(str) {
var httpxml;
try
{
httpxml=new XMLHttpRequest();
}
catch (e)
{
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)
{
document.getElementById("displayDiv").innerHTML=httpxml.responseText;
document.getElementById("msg").style.display='none';
}
}
var url="ajax-search-demock.php";
url=url+"?txt="+str;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateChanged;
httpxml.open("GET",url,true);
httpxml.send(null);
document.getElementById("msg").innerHTML="Please Wait ...";
document.getElementById("msg").style.display='inline';
document.getElementById("displayDiv").style.display='block';
}
</script>
$msg="";
if(strlen($in)>0 and strlen($in) <20 ){
$sql="select Nom_Hot, IdType_Hot, Id_Hot, IdRsrt_Hot, Dir_Hot, IdCat_Hot, Act_Hot from tbl_hotels LEFT JOIN tbl_resorts ON (tbl_resorts.Id_Rsrt=tbl_hotels.IdRsrt_Hot) where tbl_resorts.Nom_Rsrt like '%$in%' AND Act_Hot=1" ;
foreach ($dbo->query($sql) as $nt) {
$msg2="";
$int=$nt['IdCat_Hot'];
if (in_array($nt['IdCat_Hot'], array(6, 7))) {
} else {
if($int>0) { $k=0; while($k<$int) {$msg2.="<img src='site_images/orange_Star_Transparent.png' width='11' height='10' style='vertical-align:1px;' alt='gold star' />"; $k++; } } }
$msg .="<a href='hotel.php?hotel_ID=$nt[Id_Hot]&Type=$nt[IdType_Hot]&Resort=$nt[IdRsrt_Hot]' title='$nt[Nom_Hot]' class='result_Link' style='width:100%; clear:both;'><span style='text-decoration:underline; color:#E17411'>$nt[Nom_Hot]</span> <img src='images/address_Icon_2.png' height='19px' style='vertical-align:-3px;' /> $nt[Dir_Hot] $msg2</a><br/>";
}}
echo $msg;
This is the most important bit, where you either search for resort which it is below or it changes to search within the hotel name field
where tbl_resorts.Nom_Rsrt like '%$in%' AND Act_Hot=1
But on thinking about it the whole select php bit needs to change for one or the other, you couldn’t just simply change the field sorry, the hotel search is a lot easier than the resort search.
Ideally if the user skips from one radio button to the other the search starts again and possibly the text they have already entered goes away to allow them to put anew search in, quite complicated to make it work seamlessly