1

I am trying to integrate JQUERY datepicker with the following form. I can't seem to figure out why the datepicker doesn't work no matter what I try. I have looked everywhere on stack overflow and none of the solutions worked.

<html>
    <head>
        <script type="text/javascript"     src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript"     src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
        <link href="manage.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet"     href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" type="text/css" media="all">
            <script>
    $(document).ready(function() {
     $(function() {
        $( "#startdate" , "#enddate" ).datepicker( {dateFormat: 'yyyy-mm-dd' }   );

      });
    });
    </script>
        </head>
        <body>
            <form action="" method="POST" name="form1">
                <label>
                    <b>Start Date</b>
                    <span class="style1">*</span> (format YYYY-MM-DD)   
                </label>
                <br />
                <input type="text" name="time_start" id="startdate"/>
                <br/>
                <br/>

          **strong text**
                <label>
                    <b>End Date</b>
                    <span class="style1">*</span> (format YYYY-MM-DD)   
                </label>
                <br />
                <input type="text" name="time_end" id="enddate"/>
                <br/>
                <br/>
            </form>
        </body>
    </html>
2
  • what is manage.css? Commented Dec 6, 2016 at 19:54
  • Just the css for the page. Its a basic form. Commented Dec 6, 2016 at 19:54

1 Answer 1

1

just replace $( "#startdate" , "#enddate" ) with $( "#startdate, #enddate" ). Your code will work

I just added class to the <input> field and use it in the script for multiple datepick. And reduced yyyy to yy for the required format. The yyyy will give you 20162016-12-07

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" type="text/css" media="all">
        <script>
            $(document).ready(function() {
                $(function(){$('.datepick').datepicker( {dateFormat: 'yy-mm-dd' } ); }); 
            });
        </script>
    </head> 
    <body>
        <form action="" method="POST" name="form1">
            <label>
                <b>Start Date</b>
                <span class="style1">*</span> (format YYYY-MM-DD)   
            </label>
            <br />
            <input type="text" name="time_start" class="datepick" id="startdate"/>
            <br/>
            <br/>
            <label>
                <b>End Date</b>
                <span class="style1">*</span> (format YYYY-MM-DD)   
            </label>
            <br />
            <input type="text" name="time_end" class="datepick" id="enddate"/>
            <br/>
            <br/>
        </form>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

That works! But I still don't understand why it didn't work for multiple id's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.