Public feed #530964

Adam

public text v1 · immutable
Raw Edit
·published 2007-06-02 09:10 UTC
rendered paste body
<?php
include("dbconnect.php");
?>
<HTML>
<HEAD>
<style type="text/css">
body{
	background-repeat:no-repeat;
	font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
	height:100%;
	background-color: #FFF;
	margin:0px;
	padding:0px;
}
select{
	width:150px;
}
</style>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
var ajax = new sack();
var makeSel;
var modelSel;
var yearSel;

function getModelList(sel, boxSel)
{
	var boxSelection = boxSel;
	var selCode = sel.options[sel.selectedIndex].value;
	var url;
	if(boxSel = makeSel)
	{
		document.getElementById('modelName').options.length = 0;	// Empty model select box
		if(selCode.length>0){
			url = 'getModels.php?makeCode='+makeCode;
			ajax.requestFile = 'getModels.php?makeCode='+makeCode;	// Specifying which file to get
			ajax.onCompletion = createModels;	// Specify function that will be executed after file has been found
			ajax.runAJAX();		// Execute AJAX function
		}
	}
	else if(boxSel = modelSel){
		document.getElementById('yearRange').options.length = 0;	// Empty yearRange select box
		if(selCode.length>0){
			ajax.requestFile = url+'&modelCode='+modelCode;	// Specifying which file to get
			ajax.onCompletion = createYears;	// Specify function that will be executed after file has been found
			ajax.runAJAX();		// Execute AJAX function
		}
	}
	else if(boxSel = yearSel){
		document.getElementById('makeType').options.length = 0;	// Empty makeType select box
		if(selCode.length>0){
			ajax.requestFile = url+'&yearRange='+yearRange;	// Specifying which file to get
			ajax.onCompletion = createMakeType;	// Specify function that will be executed after file has been found
			ajax.runAJAX();		// Execute AJAX function
		}
	}
	
}

function createModels()
{
	var obj = document.getElementById('modelName');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}
function createYears()
{
	var obj = document.getElementById('yearRange');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}
function createMakeType()
{
	var obj = document.getElementById('yearRange');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}
		
</script>
</HEAD>
<BODY>
<form action="" method="post">
<table>
	<tr>
		<td>Make: </td>
		<td><select id="makeName" name="makeName" onchange="getModelList(this, makeSel)">
			<?php
				$query = 'SELECT DISTINCT makeName FROM `makesmodels`';
				$result = mysql_query($query) or die(mysql_error()); 
				while($myrow = mysql_fetch_array($result))
					{
						echo "<option value = \"$myrow[makeName]\">$myrow[makeName]</option>";
					}
			?>
		</select>
		</td>
	</tr>
	<tr>
		<td>Model </td>
		<td><select id="modelName" name="modelName" onchange="getModelList(this, modelSel)">
		</select>
	</tr>
	<tr>
		<td>Year Range </td>
		<td><select id="yearRange" name="yearRange" onchange="getModelList(this, yearSel)">
		</select>
		</td>
	</tr>
		<tr>
		<td>Make Type </td>
		<td><select id="makeType" name="makeType">
		</select>
		</td>
	</tr>
</table>
</form>
</BODY>
</HTML>