Skip to main content
Kinetic Community

Copy menu options

At times, there is a need to use javascript to copy the menu values from one menu to another menu.  This sample function will to that.

Resolution

Insert this javascript into your Request and modify it to use your questions menu labels.

 

//This function will duplicate menu options from the "Source" question to the "Destination" questions.


function copyMenus() {
    var s1 = KD.utils.Util.getAnswerLayer("Source");
    var opts = s1.firstChild.options;

    //this example sets the values into 3 questions Destination 1-3
    var s2 = KD.utils.Util.getAnswerLayer("Destination 1");
    var s3 = KD.utils.Util.getAnswerLayer("Destination 2");
    var s4 = KD.utils.Util.getAnswerLayer("Destination 3");

    for (var i = 0; i < opts.length; i++) {
      s2.firstChild.options[i] = new Option(opts[i].innerHTML, opts[i].value);
      s3.firstChild.options[i] = new Option(opts[i].innerHTML, opts[i].value);
      s4.firstChild.options[i] = new Option(opts[i].innerHTML, opts[i].value);
    }
}