jeudi 20 février 2020

I'm trying to use checkbox as condition

So what I'm trying to do is this: The user basically chooses date with input type='date', but if the user clicks a checkbox right next to it, the input type='date' will be replaced with the current date and time. And here is the code I wrote:

        function myFunction() {
            if($("#checkbox").checked == true) {
                $("#input_date").hide();
                var now = new Date();
                $("#current_datetime").text(now).show();
            } else if($("#checkbox").checked == false) {
                $("#current_datetime").hide();
                $("#input_date").show();  
            }
        }

In the #checkbox in html code, I have onClick="myFunction".

As well, #current_datetime, which is simple text in span tag, and #input_date are located in the exactly same spot on the page.

But the function just won't work. There is no change at all, no matter how many times I click the checkbox.

I appreciate very much for your help in advance.




Aucun commentaire:

Enregistrer un commentaire