I am working off a snippet of someone else's code I have found. I would like to update a PHP variable once the select field has changed.
The name of the of the variable is $ProductType as below. The current code does what is expected so now all I'd like to do is set the variable equal to the changed option
<?php
$ProductType = '';
if(isset($_GET['trade'])){
//Everything in here will get echoed in the DIV
echo "You selected: ".$_GET['trade'];
$ProductType = $_GET['trade']; // I'd have thought this might work but when I echo $ProductType, it returns nothing.
exit;
}
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<form name="x" action="" method="POST">
<select name="trade" onchange="$('#extra').load('?trade='+this.value);">
<option value="1">item1</option>
<option value="2">item2</option>
<option value="3">item3</option>
<option value="4">item4</option>
</select>
<input type="submit" value="SEARCH" class="submit-button btn" />
</form>
<div id="extra" style="color:red;"></div>
EDIT:
I've added a search button this time. I've echoed it out again and it seems it is working, however, it is returning an array which is not what I am after. So once the page loads, the user will select from the dropdown and the variable $ProductType should change. If I then submit the form, the page loads again and my variable updates my query.