I have two radio buttons and I want to display an alert when one of them is checked, it seems that the problem is that it doesn't recognize the element because the alert doesn't pop up!
This code used to work but it doesn't anymore (I think I changed the Id of one of the elements and that's what caused the issue)
JS:
/*This function is responsible for for the radio buttons*/
$(function() {
$(".r1").checkboxradio({
icon: false
});
});
/*This function changes the RecordTypeId according to the BankEmployeeCheckbox*/
$("form input:radio").change(function() {
if ($(this).val() == "Yes") {
document.getElementById("recordType").value = "01220000000FdvyAAC";
alert("Yes");
} else {
document.getElementById("recordType").value = "01220000000FffjAAC";
console.log(document.getElementById("recordType").value);
alert("No");
}
});
HTML
<form method='post' id='prechatForm' autocomplete="on">
<div id="bankEmployeeYesNoRadioButtonDiv">
<label>{!$Label.Bank_Employee}</label><br/>
<label for="radio-1" class="radioLabel">{!$Label.Yes}</label>
<input type="radio" name="liveagent.prechat:BankEmployee" id="radio-1" class="r1" value="Yes"></input>
<label for="radio-2" class="radioLabel">{!$Label.No}</label>
<input type="radio" name="liveagent.prechat:BankEmployee" id="radio-2" class="r1" value="No"></input>
</div>
</form>
Result: When I click on a radio button nothing happens, no alert. No Console Errors Notes: Please note that I'm using Salesforce (Visualforce) syntax.