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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -