bookthief
bookthief

Reputation: 2451

how to append a list on another page html

My html page has a list of people's names, with a button at the bottom that says 'Add new'. On clicking this button, a pop up page opens. This page has a form to collect a new name. I want to add this name to the original list. This is my javascript which works perfectly to append a list on the same page as the text box:

<script>
    $('#add').click(function(){
        var text = $('#input').val();
        if (text.length){        
            $('ul.list-group').append('<li class="list-group-item">' +text+'</li>');
        }
    });
</script>

How can I edit it so that it appends the list on the original page?

Upvotes: 0

Views: 547

Answers (1)

J&#233;r&#233;my Dutheil
J&#233;r&#233;my Dutheil

Reputation: 6137

What type of popup do you use ? With a classical popup (ie a "new page"), you can't do this with Javascript because it requires server-side treatment (Javascript is only for client, and so can only play with the current page DOM)

However, you can use something like Bootstrap Modal, that is just a "popup-like" append to the DOM ; then you can easily modify your first list. ;)

Upvotes: 1

Related Questions