Alert call not working on a button click event.

3804
2
Jump to solution
04-29-2015 09:57 AM
ChrisSergent
Regular Contributor III

I have this button in an HTML file and the following JavaScript in a JS file:

<button class="btn btn-primary" name="btnFeedback" onclick="sendEmail()">Submit</button>

function sendEmail() {

        alert("Hello");

    }

but the alert will not run when I click on the button. I receive, sendEmail is undefined. Here is the whole project where I have the code. The JavaScript file is in app/main.js

https://github.com/csergent45/streetSigns

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

In general its best to avoid using event attributes.  Instead try using dojo/on to hook up the click event. So your code would look like this instead:

on(dom.byId("idForYourButton"), "click", function(){
    sendEmail();
});

View solution in original post

2 Replies
KellyHutchins
Esri Frequent Contributor

In general its best to avoid using event attributes.  Instead try using dojo/on to hook up the click event. So your code would look like this instead:

on(dom.byId("idForYourButton"), "click", function(){
    sendEmail();
});
ChrisSergent
Regular Contributor III

Thanks for the Event attributes sample.

0 Kudos