I have 3 lists in HTML format in the same page. When ever an option is selected it is submitted and based on the selection in the first list, the second list is populated, then according to the selection of the second list the third list is populated.
Each time a choice is made the form is submitted. This is done using the following code which pertains to the HTML form:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" >
//Auto submit form
$(document).ready(function() {
$('#PrimaryCatForm, #SecondaryCatForm, #TertiaryCatForm').on('change', function() {
$(this).submit();
});
});
</script>
Everytime a selection is made I have another jquery to centralise the selection similar to this - http://jsfiddle.net/BA39h/1/
I use the followin jQuery
<script type="text/javascript" >
$(document).ready(function() {
$('#primary_cat_select, #secondary_cat_select, #tertiary_cat_select').on('change', function(){
var n = this.getAttribute('size'),
i = this.selectedIndex,
l = this.options.length;
this.selectedIndex = Math.min(l-1,i+n/2|0);
this.selectedIndex = Math.max(0,i+1-n/2|0);
this.selectedIndex = i;
})
});
</script>
When a selection is made, the selection is submitted. Unfortunately a few miliseconds after the selection is centred, the form is submitted and the selection looses it centralisation. I tried many methods to solve it but I didn't seem to manage.
The html options are populated using PHP and PDO.