php - how to dropdown option keep selected after page loads onchange -
how can dropdown option keep selected after loading page function onchange? can load page according selected value dropdown. , after loading page it's selected first value default.
<select id="extdropdown"> <option>select extension</option> <option value="*">all</option> <option value="zip">zip</option> <option value="rar">rar</option> <option value="php">php</option> <option value="html">html</option> <option value="htm">htm</option> <option value="jpg">jpg</option> <option value="bmp">bmp</option> <option value="txt">text</option> <option value="docs">docs</option> <option value="xlsx">xlsx</option> <option value="xls">xls</option> </select> $( document ).ready(function() { $( '#extdropdown' ).bind( 'change', function( e ){ document.location.href = "?dir=<?php echo $dir; ?>&action=loadfiles&ftype=" + $( ).val(); }); });
since using jquery, can this
$( document ).ready(function() { // pre-select existing choice (if any) $( '#extdropdown' ).val( '<?php echo $ftype; ?>'); // register further changes dropdown option $( '#extdropdown' ).bind( 'change', function( e ){ document.location.href = "?dir=<?php echo $dir; ?>&action=loadfiles&ftype=" + $( ).val(); }); });
update fixed typo
Comments
Post a Comment