Pawan
Pawan

Reputation: 4409

( input type = date ) display calender when clicking on box

I am using <input type="date" name="bday"> and it displays calender when I click on right side of box as follows..

enter image description here

Now I want to display calender when I click on any part of box..What should I code to achieve that..

enter image description here

Upvotes: 6

Views: 20317

Answers (2)

Carljul
Carljul

Reputation: 111

How about this? It works on mine.

<style type="text/css">
    input[type="date"]::-webkit-calendar-picker-indicator {
        background: transparent;
        bottom: 0;
        color: transparent;
        cursor: pointer;
        height: auto;
        left: 0;
        position: absolute;
        right: 0;
        top: 0;
        width: auto;
    }
</style>
<input type="date">

Upvotes: 9

seahorsepip
seahorsepip

Reputation: 4809

Edit3:

Seems even Firefox does not support the input date element...

So this might a nice hack for chrome but if you want an actual proper cross browser date input element consider using some library/plugin.

Edit2:

Tested in IE11, seems to not even support the date input element....Just hide ".picker" for IE11 I guess.

Edit:

Impossible made possible: https://jsfiddle.net/65p0et7z/

It's a dirty css/js hack which I haven't tested on other browsers besides chrome.

html:

<div class="wrapper">
    <input class="date" type="date">
    <input class="picker" type="date">
</div>

js(jQuery):

$(".picker").on("change", function() {
    var date = $(this).val();
    $(".date").val(date);
})

css:

.wrapper {
    position: relative;
    width: 146px;
    height: 24px;
    margin: 20px;
    overflow: hidden;
}
.date {
    border: 0;
    width: 146px;
    height: 24px;
    line-height: 24px;
    position: absolute;
    top: 0;
    left: 0;
    background: #fff;
    border: 1px solid #999;
    box-sizing: border-box;
}
.picker {
    width: 200px;
    height: 24px;
    font-size: 999px;
    opacity: 0;
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
}

Sorry it isn't possible, I tried to simulate a click event on the dropdown arrow but that didn't seem to work either, I'm gonna try and see if I can do something with a little visual hack :P

Upvotes: 0

Related Questions