Get next value of choice field
Hello,
I have a choice field and a text field. I need to create a expression for the text field to calculate the next value of the choice field.
For example, choice field has options "A","B","C","D". If I select "B", the text field need to return "C", if I select "C", the text field need to return "D".
What would be the way to accomplish this?
Thanks in advance
-
Please try this Calculated expression:
var valueToSelect = "";
var selected = [[YourChoiceFieldName]];
var inputs = jQuery("input[id^='YourChoiceFieldName']");
var selectedIndex = 0;
inputs.each(function(i, e){
var optionValue = jQuery(e).val();
if(optionValue === selected){
selectedIndex = i;
}
});
var nextElement = inputs[selectedIndex +1];
if(nextElement){
return jQuery(nextElement).val();
}else{
return selected;
}Do not forget to change field name used in the script.
0 -
Hello,
thank you for your answer.
The expressions is returning a value, but its always the same value as chosen.
Problems that I've noticed:
var optionValue does not loop, selectedIndex stays always 0 like its defined.
var nextElement stays undefined and the last part else{return selected;} is always triggering.
0 -
Please make sure that you define correct id:
0 -
Great, its working now, the problem was in the script above, this line:
var inputs = jQuery("input[id^='YourChoiceFieldName]']");
I was double clicking the names so the bracket left there.
Thank you, great solutions.
0 -
Thank you! Please feel free to contact us in case of further difficulties.
0
Please sign in to leave a comment.
Comments
5 comments