function update(){ $.getJSON("/main/ajax_select_route",{from: $("select#from").val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { options += ""; } $("select#to").html(options); }) } $(document).ready(function(){ $("select#from").change(update); $("select#from").val(""); $("input#show").click(function(event) { if ($("select#to").val() != 0) window.location = $("select#to").val(); }); update(); })