Hey guys, currently I am writing a script that will allow users to use a html drop down menu to select regions of the world (based on entry in a js file). We need the results to be compared against a database and return another answer without the user using any submit button.

So basically lets say it was a locator script for snacks. The user wanted to select "Chocolate Cookie" well on the drop down menu they would select "snack" then on the next field that actively changes they would select "cookie" then "chocolate" the script would then check the databases for snacks that fall into those categories and display "Chocolate cookie" and "chocolate chip cookie" however if the user only selects "cookie" then "chocolate chip cookie" "chocolate cookie" "ginger snap" and "oreo" should all display etc.

The code I am working with:

<html>
<head>
<title>Region > Country > Division</title>
<style type="text/css">

body {
	background: #fff;
}
#widget {
	width: 780px;
	height: 480px;
	font: normal 10px verdana;
	text-align: center;
	margin: 40px auto;
	border: 5px #aaa;
	border-style: outset inset inset outset;
	background: url();
}
form {
	width: 98%;
	margin: 200px 0 60px 0;
}
select {
	width: 190px;
	font: normal 11px verdana;
	color: #000;
	background: #fff;
}
#txtregion {
	width: 98%;
	height: 16px;
	font: normal 12px verdana;
	letter-spacing: .4em;
	margin: auto;
	border-bottom: 1px black solid;
}
#txtplacename {
	width: 98%;
	height: 16px;
	font: normal 10px verdana;
	margin: auto;
}

</style>
<script type="text/javascript" src="city_state.js"></script>
</head>
<body>
<div id="widget">
<form>
Region&raquo; <select onchange="set_country(this,country,city_state)" size="1" name="region">
<option value="" selected="selected">SELECT REGION</option>
<option value=""></option>
<script type="text/javascript">
setRegions(this);
</script>
</select>
Country&raquo; <select name="country" size="1" disabled="disabled" onchange="set_city_state(this,city_state)"></select>
City/State&raquo; <select name="city_state" size="1" disabled="disabled" onchange="print_city_state(country,this)"></select>
</form>
<div id="txtregion"></div>
<div id="txtplacename"></div>
</div>
<script>
<?php

  // Get the search variable from URL

  $var = @$_GET[''] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10; 

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database
mysql_connect("localhost","username","password"); //(host, username, password)

//specify database
mysql_select_db("database") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "select * from the_table where 1st_field like \"%$trimmed%\"  
  order by 1st_field"; // specify table and field names for the SQL query

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
  
?>
</script>
</body>
</html>

Please bare in mind my experience in PHP is limited most of this code was made by a developer that I am no longer in contact with so I will need things in laments terms - thanks in advanced for your help guys.

You need AJAX TO Perform this work.

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.