Tom Tom - 7 months ago 41
HTML Question

How to make a button to switch between two functions?

I have very simple html page with a button like this:

<button id="numberonebutton" onclick="buttonClick()">Start</button>

And I have separate .js file to include the javascript things. I am google the net for hours now but can't find a solution to this, but this could be my bad, sorry... I want this button to call a function when clicked. It works fine, buttonClick() is calledd succesfully. But I want to change the label of this button from Start to Stop (I already can do this) and when it is in the Stop stage, then call another function, not buttonClick(). How can achieve that? I know I can read the text from the button and make an if/else thing, but that just seems a crappy workaround. Isn't there a more professional way? I am a newbie at this...


Change the onclick attribute of the button with javascript:

var Foo = function(){
document.getElementById( "numberonebutton" ).setAttribute( "onClick", "javascript: Boo();" );

var Boo = function(){