Have an idea?

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

Custom JavaScript Verification issue

Hi, I am new to the software and trying to figure everything out. I have searched the forums and cannot figure out what I am doing wrong with my custom javascript verification. I have two grid questions with 3 blanks for numerical answers. They collect birthdate info. I need them to match. I am trying to code for the second question to display an error if they do not match. This is my current code:

[code]

if (SSI_GetValue("bday7_r1_c3") <> [%GetValue("birthd7_r1_c3")%])
{
    strErrorMessage = "Birthdate does not match.  Confirm correct date.";
}
else if (SSI_GetValue("bday7_r1_c1") <> [%GetValue("birthd7_r1_c1")%])
{
    strErrorMessage = "Birthdate does not match.  Confirm correct date.";
}
else if (SSI_GetValue("bday7_r1_c2") <> [%GetValue("birthd7_r1_c2")%])
{
    strErrorMessage = "Birthdate does not match.  Confirm correct date.";
}

[\code]

bday7 is on a previous page and birthd7 is on the current page. I have tried using SSI_GetValue, [%GetValue()%], [%questionname%], and all kinds of other variations. I am missing something and can't figure out what. I cannot make it give me an error message!! Any help is appreciated.
asked Jan 20, 2015 by ab3886 (310 points)

1 Answer

0 votes
SSI_GetValue is a JavaScript function, which deals with information on the page.  If bday7 is on a different page, the data is stored in the database for that respondent and is not present on the page, and hence isn't accessible on the page using JavaScript.  Previous answers can be referenced using normal SSI scripting tags.  An example would look like this:

if([%bday7_r1_c1%] != SSI_GetValue("birthd7_r1_c1"))

The reason this works is that SSI Scripting is evaluated on the server before the page loads.  So, if I put in a 5 on bday7_r1_c1, the next page loads like this

if(5 != SSI_GetValue("birthd7_r1_c1")

I suspect perhaps you just had a syntax error with the code you wrote.  I would recommend simplifying your code first, such as starting off with something like if([%bday7_r1_c1%] > 0) {str...} to make sure you are referencing things correctly.  Alert boxes also work really well for testing that you are capturing things correctly.  Once you have confirmed you are referencing the two variables correctly, you should be able to combine it together and get the desired result.
answered Jan 21, 2015 by Brian McEwan Gold Sawtooth Software, Inc. (38,015 points)
...