Mvc Javascript Not Working

11,830

Solution 1

This actually has nothing to do with ASP.NET, C# or Razor. This is pure HTML and JavaScript. You have wrapped the click function in pageLoad which is not being called. So you simply have to remove it.

<html>

<head>
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
</head>

<body>
    <input type="button" id="btn_click" value="Click" />
    <script type="text/javascript">
      $('#btn_click').click(function() {
        alert('You Clicked Button');
      });
    </script>
</body>

</html>

Solution 2

For button

<input type="button" id="btn_click" value="Click" />

Use javascript as-

function showalert(){
     alert('You Clicked Button');
}    
document.getElementById("btn_click").onclick = showalert;
Share:
11,830

Related videos on Youtube

Teja
Author by

Teja

Am Dotnet Developer

Updated on August 01, 2022

Comments

  • Teja
    Teja almost 2 years

    In Mvc Javascript Is Not Working Button Click Event I Want To Raise Button Click Event.

    <input type="button" id="btn_click" value="Click" />
    <script type="text/javascript">
        function pageLoad() {
            $('#btn_click').click(function () {
                alert('You Clicked Button');
            });
        }
    </script>
    

    Please Help me