Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:55:14+00:00 2026-05-26T17:55:14+00:00

I’m trying to do dynamic sortable list with link Add Destination such as Google

  • 0

I’m trying to do dynamic sortable list with link “Add Destination” such as Google – Get directions screenshot below. Big problem is that in sorted inputs sequence IDs should be maintained and the contents changed after draging. Input is able to drag before “A” and last, remove by “x” right field. Adding additional waypoints, judging by this: directions-waypoints tutorial should be get as array in JavaScript, waypoints is always middle “A” and last fields, input point “A” always name eg. “from”, last “goal”. I would like to do latter fields filling by autosuggestion from Google places. I was looking everywhere for some solution but its is too different.

EDIT: I collected everything from different sources end I got in result not quite good code: jsfiddle.net/fasE5/5/

http://maps.google.com/maps?hl=en&tab=wl

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:55:14+00:00Added an answer on May 26, 2026 at 5:55 pm

    Here is a complete working example: http://jsfiddle.net/fasE5/19/

    The HTML I came up with:

    <div id="sortable" class="isOnlyTwo">
         <div class="destination">
            <span class="handle">A</span>
            <input type="text" name="dest1" value="" />
            <a href="#" class="remove_input">&times;</a>
         </div>
        <div class="destination">
            <span class="handle">B</span>
            <input type="text" name="dest2" value="" />
            <a href="#" class="remove_input">&times;</a>
         </div>
    </div>
    <a href="#" id="add_input">Add Destination</a>
    

    And the CSS, to make it look a little more pretty:

    #add_input
    {
        text-decoration:none;
        color:#15C;
        margin-left:35px;
    }
    #add_input:hover
    {
        text-decoration:underline;
    }
    .placeholder
    {
        border:2px dashed #bfbfbf;
        margin:5px;
        width:240px;
    }
    .handle
    {
        background-color:#06B500;
        border:2px solid #3D7311;
        cursor:n-resize;
        padding:0 3px;
        border-radius:99px;
        font-size:12px;
    }
    .destination
    {
        margin:5px 15px;
    }
    .destination input
    {
        border:1px solid #B9B9B9;
        width:200px;
    }
    #sortable.isOnlyTwo .remove_input
    {
        display:none;
    }
    .remove_input
    {
        color:#999;
        text-decoration:none;
        font-weight:bold;
    }
    .remove_input:hover
    {
        color:#666;
    }
    .destination.ui-sortable-helper
    {
        opacity:0.8;
        filter:alpha(opacity=80);
    }
    .destination.ui-sortable-helper .remove_input
    {
        display:none;
    }
    

    To keep the right order of the input‘s name attribute and the order letters (A, B, C…), we call to RecalculateOrder on sort update and when removing an destination.

    To prevent from removing the last 2 destinations, we add an isOnlyTwo class to the #sortable div when there is only 2 destinaitons left. Which thanks to our CSS hides the remove_input.

    For the autocomplete we need GoogleMaps API

    <script src="//maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
    

    Which provides us an new google.maps.places.Autocomplete(input) to add google’s autocomplete functionality.

    $(function(){
        $("#sortable").sortable({
            containment: "document",
            placeholder: 'placeholder',
            handle: ".handle",
            axis: "y",
            update: RecalculateOrder,
            forcePlaceholderSize: true
        });
    
        $("#add_input").click(function () {
            var inputIndex = $("#sortable > .destination").length;
    
            // Building the new field's HTML
            var html = '<div class="destination">';
            html += '<span class="handle">' + String.fromCharCode(inputIndex + 65)  + '</span> ';
            html += '<input type="text" name="dest' + (inputIndex + 1) + '" value="" /> ';
            html += '<a href="#" class="remove_input">&times;</a>';
            html += '</div>';
    
            var newField = $(html);
            newField .find(".remove_input").click(RemoveInput);
            $("#sortable").append(newField ).removeClass("isOnlyTwo");
    
            // Adding autocomplete to the new field
            BindAutoComplete(newField.find("input")[0]);
    
            return false;
        });
    
        $(".remove_input").click(RemoveInput);
    
        // Adding autocomplete to the first two fields
        $("#sortable input").each(function(){
            BindAutoComplete(this);
        });
    
        function RemoveInput()
        {
            $(this).parent().remove();
            RecalculateOrder();
            var isOnlyTwo = $("#sortable > .destination").length == 2;
            $("#sortable").toggleClass("isOnlyTwo", isOnlyTwo);
            return false;
        }
    
        // Recalculating from scratch the fields order
        function RecalculateOrder()
        {
            $("#sortable .handle").text(function(i) { 
                return String.fromCharCode(i + 65); 
            });
    
            $("#sortable input").attr("name", function(i){
                return "dest" + (i + 1); 
            });
        }
    
        function BindAutoComplete(input)
        {
            var autocomplete = new google.maps.places.Autocomplete(input);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.