jeudi 21 mai 2015

Event handler firing multiple times

I have this very odd and strange situation. I attached a click listener to a radio-button just once. However, when I click the radio button, the listener function fires twice. I tried it using both jQuery and plain JS event handlers, and it's the same problem.

Here's the HTML:

<input type="radio" id="type_oneway" name="type" value="One Way" class="use_once" checked style="display:none;"><label for="type_oneway" style="width:74px;">One Way</label>
<input type="radio" id="type_roundtrip" name="type"value="Roundtrip" class="use_once" style="display:none;"><label for="type_roundtrip" style="width:74px;">Round Trip</label>

Javascript code, I replicate the jQuery version here:

$("#type_oneway").on("click", function(){ alert('clicked button'); });

When I run the code and click the button, I get two alerts. I can't seem to figure out the reason.




Aucun commentaire:

Enregistrer un commentaire