How to associate Javascript functions with buttons? -


javascript

html

i feel though doing correctly, whatever reason, isn't working. i've made sure link javascript file present , in correct syntax.

 <script src="speedreader.js" type="text/javascript"></script> 

in header.

i have

<button id="start" onclick="start();" type="button">start</button> 

this obstrusive javascript, won't work

    var startbutton = document.getelementbyid("start");     startbutton.onclick = start; 

so i've had no choice resort it.

my function i'm attempting associate button basic thing. test see if javascript function work @ all.

function start() {         alert("this working");     } 

if you're loading script in header , trying getelementbyid there, the element won't yet parsed/created.

put <script> tag loads script @ end of page, or @ least listen dom ready before try bind elements.


Comments