I have a form with several radio buttons that have 3 associated values:
- Red (Highest Priority): link.com/3
- Orange (Higher Priority): link.com/2
- Green (Working): link.com/1
I need to trigger redirects to different links based on the users selections, if the user selects answers which are all associated to the ID #sCgreen
then the redirect works. What I need to do is override this:
- If the user selects any orange answers (
#sCorange
) this should override the green redirect; - If the user selects any red answers (
#sCred
) this should override both the green and the orange redirect;
Is there a way to prevent each event from firing if the higher priority event is triggered, or to prioritise the events accordingly?
$('#continue').click(function(event) {
event.preventDefault()
// Red triggered.
if(document.getElementById('sCred').checked) {
window.open("https://link.com/3","_self")
return;
}
// End red triggered.
// Orange triggered.
if(document.getElementById('sCorange').checked) {
window.open("https://link.com/2","_self")
return;
}
// End orange triggered.
// Green triggered.
if(document.getElementById('sCgreen').checked) {
window.open("https://link.com/1","_self")
}
// End green triggered.
});
Any help would be greatly appreciated!
EDIT: added return;
, there are multiple instances of the input ID's so this only works on the first 3 instances of the questions.