Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

get question type and select type

Hi guys,

Could you please tell me how to get question type and Select type (Radio button / Checkbox) using javascript or sawtooth software function....
please respond as soon as possible...

Regards: Nouman. S
asked Oct 8, 2018 by Nouman Saeed Bronze (975 points)
Every question at runtime has an ID to the effect of "QUESTIONNAME_div" and two classes: a class "question" and another class that relates to what sort of question it is.  Select questions have a "select" class, open-ends an "openend" class, etc.

Determining certain properties of questions can sometime be more tricky, but is usually possible.  For example, a select question with radio buttons will have an element that matches ".select input[type=radio]"; checkbox and dropdown select questions won't have such an element.

If you can tell me more about what you are trying to achieve with this, I could offer more specific information.
Thanks Zach.. for your response..
basically i want to auto submit all select question on selection of radio button  
for this purpose i m using this Code
function SSI_CustomGraphicalRadiobox() 

in HTML <head> Tag under "setting / Header and Footer/..."
but i want to avoid radio buttons in grid & more than 2 select questions on same page...
thank you..

1 Answer

0 votes
I recommend only placing code in the HTML head tag if it applies to multiple / most / all question pages.  If you want to add some logic to only one question, you can add the code to the question itself.  Select question's have their own HTML head tag that can be used.  Or, alternatively, some users place special question code into the question's footer.

This will solve the problem of not wanting your code to apply to questions on other pages, but the JavaScript you put into one question can still affect any other questions on the same page.  To handle that, we're going to want to make use of SSI_CustomGraphicalRadiobox's parameters.  The second parameter has a "name" property that will tell us the name of the select question that was clicked on.

This example will only trigger the auto-submit if the radio button was from a question named "SelectQ":

function SSI_CustomGraphicalRadiobox(graphicalObj, inputObj) {
    if (inputObj.name == 'SelectQ') {
answered Oct 10, 2018 by Zachary Platinum Sawtooth Software, Inc. (116,925 points)
thanks Zach, but i have multiple question around 50 select question, is this possible through array using loop, if yes please respond.
Between lines 2 and 3, you can define an array of question names like this:

var questions = ['Q1', 'Q2', 'Q5', 'Q7'];

Then replace the if statement's test like this:

if (questions.includes(inputObj.name)) {