יותם דהן
יותם דהן

Reputation: 69

JS Canvas Function

<script>
    function confirm() {
        if (document.getElementById("myInput") == "12") {
            var c = document.getElementById("myCanvas");
            var ctx = c.getContext("2d");
            ctx.moveTo(130, 0);
            ctx.lineTo(130, 150);
            ctx.stroke();
        }
    }
</script>
<input type="text" id="myInput" placeholder="Type Your Hour" class="center" />
<input type="submit" value="OK" id="button" class="center" onclick="confirm();" />

I've got this code to get canvas px or postion, and i got stuck on the confirm function, i tried use myInput id to get input and equal it to 12, but the code not working.

How can i fix that to work?

Thanks in advance!

Upvotes: 0

Views: 77

Answers (1)

David G
David G

Reputation: 96800

Your if statement is not checking equality correctly. If you want to know what the user typed, then you must take that information from the value attribute:

if ( document.getElementById("myInput").value == "12" )
//                                      ^^^^^

Upvotes: 3

Related Questions