I have the following which calls another file and spits output based on the dropdown value. It works fine except I can't seem to get it to work correctly without a submit button. This works except it will redirect itself to process.php with the correct output. The whole point of this code is to display the output within the empty div (output).
$(document).ready(function() {
$('#dropdown').change( function() {
$('#myform').submit();
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#output').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
});
<form id="myform" method=POST action="process.php">
<select id="dropdown" name="dropdown">
<option value="QU">QU</option>
<option value="QF">QF</option>
<option value="QC">QC</option>
</select>
</form>
<div id="output"></div>
outputdiv. It works fine but, if there's a better way, I'm open to it.