Issue
I have a form and the user have to select the first <select>
and it will filter the second <select>
on db and just after show to user.
I've seen it on some sites and I would like to put it on mine
The first <select>
<select name="area" id="area">
<option title="" value="">Select ...</option>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">third</option>
</select>
If I select o option with value 1, it will search on MySQL all lines with id=1
SELECT * FROM tblarea WHERE id_prof = 1;
And this result will make second select
<select name="prof" id="prof">
<option title="" value="">Select ...</option>
<option value="1">1.1</option>
<option value="2">1.2</option>
<option value="3">1.3</option>
</select>
While the query is working it will show on <select>
"Searching ..."
If I am thinking wrong please help me, and give me ideas.
Thanks
Solution
As @dontHaveName suggested, use an Ajax call that will look something like this:
$('#area').on('change', function(e) {
$.ajax({
url: '/jobs/options/',
type: 'POST',
data: $(e.target).val(),
dataType: 'html',
success: function(opts) {
$('#prof').html(opts);
},
error: function(xhr, status, err) {
console.log(err);
}
});
});
Some of the Ajax code is from memory, so let me know if you're getting errors.
Answered By - cantera
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.