on click function of radio button/multiple choice, change to next screen | XM Community
Skip to main content

hello! I'm using radio buttons of yes/no answer. the answer is time limited, I want to change the logic, that after clicking one of the radio buttons the screen changed to next question , and not after clicking the next button. I used the following code with no success:
this.questionclick = function(event,element){
//for a single answer multiple choice question, the element type will be radio
if (element.type == 'radio') {
var choiceNum = element.id.split('~')[2];
alert('You clicked on choice '+choiceNum); }
}
please help

var qobj = this; //added
this.questionclick = function(event,element){
//for a single answer multiple choice question, the element type will be radio
if (element.type == 'radio') {
var choiceNum = element.id.split('~')[2];
alert('You clicked on choice '+choiceNum);
qobj.clickNextButton(); //added
}
}


I have 7 radio button on my survey.  Values 1 to 7 in Recode values and advanced scoring.

They all return the correct value except for the second one.  It returns 8 and not 2.

Where is this value 8 coming from?

The ID of the button is QR~QID5~1~8, it should be QR~QID5~1~2?


Hi @VJTM,
the 8 is most probably the internal ID of that scale point. Did you insert it later?

 

You can check the internal IDs in Support Mode.
In the Survey Builder, Control-Shift-Click on ‘Tools’ and enable the Support Mode (last element in the dropdown menu).

You should be able to see something like the following:

  


Hi Manfred 

The ID of the second button is QR~QID5~1~8,

So I take the 8 as the correct value which is wrong.

It should be a value of 2 as it is the second of 7 radio buttons.

I need to get the value of all the  radio buttons checked.  

 

    if (elements(i].type === 'radio')
        {        
            if (elementsi].checked)
            {
                var splitId = elements>i].id.split('~');
        
                var questionValue = splitId3];                
                
                Answers = Answers + parseInt(questionValue);
                
                totalNumberOfQuestions++;
            }
        }


There is no way (as far as I’m aware of) of changing the internal IDs of the answer choices. They are created in the order the choiced are added to the question. If you add a new choice afterwards, it automatically will get the next, unused ID - independent of where you add this choice.

(That’s intended behaviour and ensures that adding a new choice will not break any other logic)

 

You theoretically could use the recoded values (instead of the choice IDs), but those are not accessible before the respondent has progressed to the next screen.

I can see two options for you:

  1. Use a value mapping in your code
  2. Delete the question and create it all over again - making sure that you add the 8 choices in the correct order

Hi Manfred

I was starting to think that this is the case - create it all over again.

On the excel sheet with the results there is a column SC0 - I have tried to access this from JavaScript but to no avail, is there a way as this has the correct value in it?


No, not while the respondent has not advanced to the next page (and the answers are saved).

The JS code has to sit on this question?

In the next question you would be able to access the (correct) recoded values.


The JavaScript has to make some calculations on this page and set the embedded Data up with the results.  I think we need as you say to not change the radio buttons.

Thank you for your help Manfred in clarifying this.


@VJTM,

You can use recode values. You can use the JS API. Where ‘this’ is question object:

To get recode from choice id: this.getChoiceRecodeValue(choiceId)

To get choice id from recode: this.getChoicesFromRecodeValue(recodeVal)

Since it is possible to assign the same recode to multiple choices getChoicesFromRecodeValue returns an array.


Leave a Reply