Ad

Javascript - Show Alert When Specific Radio Button Is Checked On ID

- 1 answer

I need to show a alert when someone clicks on a radio button with a specific ID.

This is the radio button:

<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="kerst_shipping_standard" id="s_method_kerst_shipping_standard">

And when someone clicks that radio button it needs to show a alert.

Ad

Answer

Try this.

document.getElementById('s_method_kerst_shipping_standard').addEventListener('click', function() {
    alert('ok');
});

I am assuming ID is unique in the document.

Ad
source: stackoverflow.com
Ad