0

I want to add a series of dates to my page. I have one input box, clicking which will open a calendar to select the date. Then on clicking the new button, another input box for selecting the date will open. I have written the code for both opening new text box and adding a datepicker but I don't know how to link the two as after calling the leave() function , the jquery function is not working. Here is my code -

<html>
    <head>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    </head>
    <body>
        <script>
            $(function() {
                $("#datepicker").datepicker();
            });
        </script>
        <script>
            function leave() {
                document.getElementById('popup').innerHTML += '<input type = text name = "element" id="datepicker" /><br />';
            }
        </script>
        <div id = "popup">
            <input type = text name = "element" id="datepicker" /><br />

        </div>
        <button id = "click" onclick = "leave();">New</button>
    </body>
</html>

1 Answer 1

1

Your leave method, removes the exising widgets to the input elements since it is overriding the current innerHTML, you need to use append()

function leave(){
    var dp = $('<input type=text name ="element"/>').datepicker();
    $('#popup').append(dp).append('<br />')
}

Demo: Plunker

Not the answer you're looking for? Browse other questions tagged or ask your own question.