Have an idea?

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

Validate open-ends in grid question i.e. if one column answered require in other column

I want to have 2 columns in a grid, if they enter text in a row in column 1 they have to enter text in column 2.

This works fine if you only have one row, the next rows mess it up if I just cut and paste it.
function c1validate(parText, parPattern)
if(parPattern.test(parText) == false && SSI_GetValue("q7_r1_c2") == "")
return "Please enter name and location.";
else {return "";}
address = SSI_GetValue("q7_r1_c1");
pattern = /^([\w])$/;
strErrorMessage = c1validate(address,pattern);

I like this because I can use regex expressions on the first one to make sure it fits a format. That isn't really necessary here though.

Any help? I absolutely know I am missing something stupid like an if {alert} and I just can't think right now!

Thanks, Jake
asked Jan 10, 2012 by j.bratton Bronze (620 points)
retagged Sep 13, 2012 by Walter Williams
Umm Jake,

this won't work for row2, row3, etc since you have hardcoded the lookup question into the function itself? (i.e. && SSI_GetValue("q7_r1_c2") )
Yep, I was planning on just repeating the statement, and got into the "if the last one returned a no error none of them would return an error".

I knew I was missing something simple, this worked fine for my purposes, I just repeated it for the 10 rows in the grid:
if (SSI_GetValue("q8_r10_c2") == "" && !(SSI_GetValue("q8_r10_c1") == ""))
 strErrorMessage = "Please enter in both name and location.";  

For some reason I just couldn't come up with reversing the terms and adding the "and not". I blame Monday.

Thanks for replying Bahadir,

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.