Have an idea?

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

Free format qustion help

I have free format question for capture Numeric response or Don’t know from the respondent. However, currently respondents can enter both numeric response and Don’t know and move to the next question. Does anyone have script to validate?

Also, the other problem is when I go back from the current question to previous question, the entered answers were missing for free format questions. Can anyone help me to fix this problem?

<table border="0" cellpadding="1" cellspacing="1" width="50%">
  <td><input name="RE7_A" id="RE7_A" type="numeric" size="3">%</td>
    <tr class="clickable">
        <td class="input_cell">
            [%CheckSelect(RE7_A1, 1)%]
            Don't know

asked Jul 5, 2012 by anonymous
retagged Sep 13, 2012 by Walter Williams

1 Answer

+1 vote
Best answer
Put the following in your custom javascript verification tab and it should do what you need to make sure they only put in a numeric value OR select the Don't Know, but not both or neither.

if ((document.mainform["RE7_A"].value).length == 0 && SSI_GetValue ("RE7_A1_1") == 0)
var strErrorMessage = "You must enter a valid number OR select Don't Know";
if ((document.mainform["RE7_A"].value).length > 0 && SSI_GetValue ("RE7_A1_1") == 1)
var strErrorMessage = "You must enter a valid number OR select Don't Know, NOT BOTH";
answered Jul 5, 2012 by Jay Rutherford Gold (27,450 points)
As far as backing up, I don't have any problem with it retaining and showing the response that was put in and I have the exact same setup.
In the samyway, I have a free format numeric questions with Don't know and Refused. I have programmed Don't know and Refused as single punch question and modified the above code little bit and it is not working

D24A - captuing number
D24B - captuing number
D24C - created as radio button  and it contains Don't know and Refused

if (((document.mainform["D24_A"].value).length == 0 && (document.mainform["D24_B"].value).length == 0) && SSI_GetValue ("D24_C") == "")
 var strErrorMessage = "You must enter a valid number OR select Don't Know/Refused";
 if (((document.mainform["D24_A"].value).length > 0 && (document.mainform["D24_B"].value).length >= 0) && SSI_GetValue ("D24_C") > 0)
 var strErrorMessage = "You must enter a valid number OR select Don't Know/Refused, NOT BOTH";
In what way is it not working?  I duplicated this question and the error message does come up.  I would suggest making D24_C a checkbox and set to allow 0 to 1 responses for it (you would also then have to modify the error code accordingly).  The reason I suggest this is once you've checked a radio button you can't uncheck it and then you are kind of stuck.