Home › Forums › JavaScript › show/hide div on date picker date change
- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
May 21, 2017 at 11:00 am #255056chauhanheenaParticipant
Hi,
I’m using a date picker.
I have two divs which have style=”display:none” as inline css.
If I select a date between 1st jan 2014 to 2 jan 2015, div 1 should show up.
If i select a date between 3 jan 2015 to 10 sep 2016, div 2 should show up.if I select nothing, or delete the selected date from the datepicker, then both div’s should hide.
How do I achieve this using Javascript and css.Thanks
May 22, 2017 at 12:41 am #255063JeroenRParticipantI guess something like this will do. Depends on what technique you use for the datepicker, but you’ll have to use a function that is fired when a value has been chosen. In that function you can check the value set against your two ranges.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <a href="https://code.jquery.com/jquery-1.12.4.js">https://code.jquery.com/jquery-1.12.4.js</a> <a href="https://code.jquery.com/ui/1.12.1/jquery-ui.js">https://code.jquery.com/ui/1.12.1/jquery-ui.js</a> $(function() { $('#datepicker').datepicker({ onSelect: function() { var date = $(this).val(); checkRange(date); } }); }); function checkRange(date) { $('#div1').hide(); $('#div2').hide(); var checkDate = new Date(date), a = new Date('2014/01/01'), b = new Date('2015/01/02'), c = new Date('2015/01/03'), d = new Date('2016/09/10'), inRange1 = checkDate >= a && checkDate = c && checkDate </head> <body> <p>Date: <input type="text" id="datepicker"></p>
DIV1DIV2</body> </html>June 1, 2017 at 7:32 am #255411chauhanheenaParticipantThanks it worked for.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.