php - Html button action only on first click -


i can set action on click html button. need set action on first click. there way this? button radio in form. javascript maybe?

what's important - radio button still might changed. action has done once.

this doesn't work

function myfunction(i){ oform = document.forms["myform"]; if(oform.elements["field"+i].checked)     alert("action done earlier"); else     action } 

the cleanest solution use removeeventlistener to... remove event listener :

var mybutton = document.getelementbyid('someid'); var handler = function(){    // dosomething    mybutton.removeeventlistener('click',handler); } mybutton.addeventlistener('click', handler); 

(to make cleaner, wrap in iife, in example below)

demonstration


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -