How can I run a PHP query which only runs when an option is chosen from a select dropdown but also which refreshes each time a different option is chosen?
For example, here is the HTML:
<html>
<head>
<script type="text/javascript" src="/hr/includes/jui/js/jquery-ui-1.8.20.min.js"</script>
<script>
$(document).ready(function() {
$('#select_box_1').change(function() {
if($(this).val() != '')
$.ajax({
type: 'get',
url: 'balance1.php',
data: 'value' + $(this).val() ,
success: function(data) {
$("#result-div").html(data);
}
});
}
});
});
</script>
</head>
<body>
<form name="form" id="form" method="post" action="validate.php">
<div id="select_box_1">
<select name="drop_down">
<option value="">Please choose</option>
<option value="1">John</option>
<option value="2">Bob</option>
<option value="3">Mike</option>
</select>
</div>
<div id="result-div">
</div>
<input type="submit">
</form>
</body>
</html>
balance1.php
<?php
print "GET Value:".$_GET['value'];
?>
I would like to run a query below the select box depending on the value chosen – for example, when nothing is chosen there is no query ran. If the user chooses John from the list then the query runs where the id=1 and displays results for John. If the user then chooses Bob, the query should run again where the id=2 and so on?
This is working:
I gave an id to the select and modified the data line (and added a few syntax corrections).