Have an idea?

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

Javascript validation 0 value Issues

Hi,

I have a free format question (Q21) with numeric text box and don't know checkbox for each attribute. I pipe in selected attributes from Q20 to Q21. The valid range for numeric text box is 0 to 100. I have written below validation script

var strErrorMessage="";

var Q20KValue='[%Q20_K%]';


if(Q20KValue>=1 && SSI_GetValue("Q21_ROW6L")=="" && SSI_GetValue("Q21_ROW6_1")==0)
{
  strErrorMessage= "Response is required for 'Specialty' attribute."
}
else if (SSI_GetValue("Q21_ROW6L")!="" && SSI_GetValue("Q21_ROW6_1")==1)
{
  strErrorMessage= "Please provide only one answer for 'Specialty' attribute."
}


var Q20IValue='[%Q20_I%]';


if(Q20IValue>=1 && SSI_GetValue("Q21_ROW5L")==="" && SSI_GetValue("Q21_ROW5_1")==0)
{
  strErrorMessage= "Response is required for 'Automated' attribute."
}
else if (SSI_GetValue("Q21_ROW5L")!="" && SSI_GetValue("Q21_ROW5_1")==1)
{
  strErrorMessage= "Please provide only one answer for 'Automated' attribute."
}


The problem is if I entered 0 in numeric textbox it throws 'Response is required' error and if I entered 0 and checked Don't know option then it doesn't throw 'Please provide only one answer' error.

But the script works fine for other values (1 to 100)
asked Aug 13, 2020 by Abdul Bronze (3,220 points)
edited Aug 13, 2020 by Abdul

1 Answer

+1 vote
 
Best answer
Hi Abdul,

Instead of SSI_GetValue("Q21_ROW6L"), please capture the value in a variable like below and then use the variable for applying any condition as you have applied:

var pq=$("#Q21_ROW6L").val();

I hope this will solve your query.

Regards,
Rahul Mittal
answered Aug 13, 2020 by Rahul Mittal Gold (11,860 points)
selected Aug 13, 2020 by Abdul
Hi Rahul,
Thank you so much. It helped me great. Awesome!
...