Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@drenther
Created September 15, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drenther/246c90bf8f4ae1a414c025d73ca179ed to your computer and use it in GitHub Desktop.
Save drenther/246c90bf8f4ae1a414c025d73ca179ed to your computer and use it in GitHub Desktop.
A tiny script to simplify Amizone feedback
function rate(rating) {
const submit = document.querySelector(`input[type="submit"]`);
submit.removeAttribute('onclick');
if (![0, 1, 2, 3, 4].includes(rating)) {
console.log("rate(0) for Strongly Agree, rate(1) for Agree, rate(2) for Neutral, rate(4) for Strongly Disagree");
} else {
const inputs = [...document.querySelectorAll(`input[type="radio"]`)];
const ratings = inputs.filter( x => x.id.endsWith(`Rating_${rating}`) );
const questions = inputs.filter( x => x.id.includes(`Question`));
const text = document.querySelector('textarea');
ratings.forEach( x => {
x.checked = true;
x.parentElement.style = "background-color: rgb(185, 222, 138)";
});
if (rating >= 0 && rating <= 2) {
questions.filter( x => x.id.endsWith('0')).forEach( x => x.checked = true );
} else {
questions.filter( x => x.id.endsWith('1')).forEach( x => x.checked = true );
}
switch (rating) {
case 0:
text.value = 'Great';
break;
case 1:
text.value = 'Good';
break;
case 2:
text.value = 'Okay';
break;
case 3:
text.value = 'Not so good';
break;
case 4:
text.value = 'Bad';
break;
}
}
submit.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment