Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
Ok, who can tell me why why why the click event never fires?


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="Scripts/jquery-3.3.1.min.js"></script>

    <script src="Scripts/anytime.5.2.0.js"></script>
    <script>
        $('#btnCalendar').click(
            function(e) {
                alert("I am an alert box!");
                $('#txtbxStartDate').AnyTime_noPicker().AnyTime_picker().focus();
                e.preventDefault();
            } );
    </script>
    <link href="Styles/AdminItems.css" rel="stylesheet" />
    <link href="Styles/anytime.5.2.0.css" rel="stylesheet" />
</head>
<body>
<input type="text" id="txtbxStartDate" runat="server" />
<button id="btnCalendar">
    <img src="./Images/calendar.png" alt="[CLickMe]" />
</button>
</body>
</html>


I'm just a poor c/c# developer.

What I have tried:

taking it out of the web app and putting in a simple html file. REading too many 'have you tried...' posts ob stackoverflow
Posted
Updated 16-Oct-18 9:31am
Comments
Kornfeld Eliyahu Peter 16-Oct-18 14:08pm    
It is very possible that you try to bind to btnCalendar before it exists...
Wrap it in $(document).ready()...
https://api.jquery.com/ready/

Javascript runs as it loads, so you are referencing btnCalendar before it exists. Move the script to the bottom of the page, or attach your event to btnCalendar in the document ready event (that runs after everything else has loaded).
 
Share this answer
 
I could be wrong, but don't you need to associate the control with the action?


onclick Event[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900