Have an idea?

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

How to check "other (specify)" field answer is numeric

My question is certainly very basic for those of you who know a little of javascript.

I want respondents to provide a number (heating costs last year) but to have the option to say "I don't know". For this I use a select question with two options, one being "I don't know" and one "Km (Specify)".

My problem is, I want them to give numbers (e.g. 1000 rather than "a thousand" or "1'234.45"). Hence I am trying to implement the following javascript custom verification, but with no luck so far;

[% Begin Unverified Perl
if(SSI_GetValue("heatingcost") ISNUMBER) {
var strErrorMessage = "";
}
else {var strErrorMessage = "bug";}
End Unverified %] 


I have very limited skills with javascript, hence I am certainly missing the elephant in the middle of the room. Any help would be welcome!

PS: actually I am not using directly a numeric question because I would really like respondents to be able to select an "I don't know" option.
asked May 21, 2014 by Albatus Bronze (545 points)

1 Answer

+1 vote
 
Best answer
First you do not need to use Begin Unverified Perl inside the custom javascript  verification.

Now, for your problem, please use below code, hope this helps you. Please replace variable name of other box with mine one(heatingcost_2_other) .

var raj=SSI_GetValue("heatingcost_2_other");
if(isNaN(raj))
{
var strErrorMessage = "The response must be numeric.";
}

answered May 21, 2014 by Rajesh Rana Gold (23,530 points)
selected May 22, 2014 by Albatus
Perfect, it works perfectly. Many thanks!
Hi ranarajesh85,

Could you help me accomplish this pre SSI_GetValue capability? I am working with an older version of SSI. Thank you!
...