Add button onclick

Hi, i have a project with a few pages. on the main pages, index.html i fave some buttons. a have create also a jsfile with document.ready function and in this function i add the onclick:

$(document).ready(function(){ $("#btnSend").on("click", function(){ alert('sending..'); }); });

This is working fine on this page. My problem is that on all other pages the onclick event was not executed. Can anybody help me? Thanks Dani

If you want that working on every page, the button you want to trigger that alert must exist on all pages with the ID of "btnSend". Also there should only be one element per page with that ID as well. And you will need to make sure that every page loads that script as well.

I don't see any reason why that wouldn't work unless you have something wrong with what I stated above.

Saj

Hi,<br /> I am a begginer and started working in bootstrap studio a few days go.. My problem is when we are using notepad or notepad++ or some simple apps to create a web page we directly add onclick event to a button but i cant add an onclick event directly to button in bstudio.. Plz someone help me how can i add an event to a button.. Thank u

Add onclick event to a button

1 Like

Thank u

Your welcome :-)

Hi drentsch, my idea:

  1. You need set id to button like: #yourbutton
  2. Add this code to js file: document.getElementById("yourbutton").setAttribute("onclick", "function(){alert(‘sending..’)}");

Good luck!