I am learning C# and JS and I am trying to create a simple questionnaire for users to answer after reading our help section. After the user selects "yes" and clicks submit, I would like for an alert to pop up saying "Thank you for using us". If user selects, "no" a different response would appear. Could somebody help me out? The error I am getting is the following:
groupOfDefaultRadios is not a function.
Could someone help me and tell what is it wrong that I am doing? I provided a snippet.
window.question1 = function() {
var option = getRVBN('groupOfDefaultRadios');
if (option == 'yes') {
alert("Thank you for your kindness");
}
else {
alert ("We are sorry! Please write to us telling us what was wrong");
}
}
function getRVBN(rName) {
var radioButtons = document.getElementsByName(rName);
for (var i = 0; i < radioButtons.length; i++) {
if (radioButtons[i].checked) return radioButtons[i].value;
}
return '';
}
function isEmptyOrSpaces(str) {
return str === null || str.match(/^ *$/) !== null;
}
<div class="clienthelp-card">
<form id="myForm">
<h4> Was this helpful?</h4>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="defaultGroupExample1" name="groupOfDefaultRadios" value="yes">
<label class="custom-control-label" for="defaultGroupExample1">Yes</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="defaultGroupExample2" name="groupOfDefaultRadios" value="no">
<label class="custom-control-label" for="defaultGroupExample2">No</label>
</div>
<input class="button" type="button" onclick="groupOfDefaultRadios();return false;" name="groupOfDefaultRadios" value="Submit">
</form>
</div>