2

There is a problem with my select box which shows them a list when they start typing, and they have to click on their city or type it correctly.

When I click on a city from the list, the matching shipping methods won't show up untill I'll press "Enter" on the box or click outside of it.

I want that the shipping methods will show up just when the client chose his city. without clicking the enter key or outside of the box.

Here is the script:

<script>
jQuery(function() {var availableTags = ["A","B","C","D"];

    function addOption(newvalue){
      if (newvalue!==''){
        // assign an id of 0 so that we know to insert into the database
        var newelement = {id:0,label:newvalue};
        availableTags.push(newelement);
        showAvailableTags();
      }
    }

    function showAvailableTags(){
      jQuery(".my-billing-city").autocomplete({
        source: availableTags,
        select: function( event, ui ) {
          // get label input box
          var $label = jQuery(this);
          $label.val( ui.item.label );
          // get hidden id box
          var $id = jQuery('#'+this.id.replace('label_','id_'));
          $id.val( ui.item.id );
          return false;
        },
        change: function( event, ui ) {
          var $label = jQuery(this);
          // figure out the id of hidden input box from label id
          var $id = jQuery('#'+this.id.replace('label_','id_'));
          if ( ui.item === null && $label.val() != '' ){
            // new value so ask user if they want to add it
            var add =             alert( "You must choose a city from the list!" );
            if (add){
              $id.val(0);
              addOption($label.val());
            }
            else{
              // not added so clear input box
              $label.val('');
              $id.val('');
            }
          }
        }
      });
    }

    // bind tags to for autocomplete
    showAvailableTags();
});

jQuery( ".ui-autocomplete .ui-menu-item" ).click(function() {
    alert( "Handler for .click() called." );
});
</script>

closed as off-topic by Qaisar Satti, Jeroen, 7ochem, mbalparda, Fabian Schmengler Jan 15 '16 at 13:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Qaisar Satti, Jeroen, mbalparda
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I'm voting to close this question as off-topic because this question is about jQuery. It doesn't belong on Magento SE. You'd have more chance of getting a good answer at StackOverflow. – 7ochem Jan 15 '16 at 12:53