Skip to content
Advertisement

JS not firing at all

I cannot get my button to trigger the javascript. This seems to be quite straightforward? What is keeping the alert from showing up?

 <script type="text/JavaScript" 
 src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">

  $(document).ready(function ()
  {
    $("#submitButton").click(function (e) {

            alert("Hello!!");
               
      });
   });
</script>


<input type="submit" name="submitButton" id="submitButton" class="form-input" value="ButtonName" 
OnClick="ActionName" runat="server" />

Advertisement

Answer

You should end of the script tag if you add source only. And you should add extra script tag for internal script. And input type should be button because you are not submitting a form in here. If you will submit something, you should use a form element and listen it’s submit event. You can use input type="submit" for it.

$(document).ready(function ()
  {
    $("#submitButton").click(function (e) {

            alert("Hello!!");
               
      });
   });
 <script type="text/JavaScript" 
 src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<input type="submit" name="submitButton" id="submitButton" class="form-input" value="ButtonName" 
OnClick="ActionName" runat="server" />
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement