Have an idea?

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

Javascript validation when element not on page

Hi. I have a javascript validation that refers to cells in a grid. The number of columns shown in the grid is dynamic - it depends on answers piped in from a previous question. My javascript validation works when all possible columns in the grid are shown... but doesn't work when not all columns are shown... this is because the javascript validation is refering to cells in the grid that are not on the page... I think I need to include in the validation, some script that first checks if the cell in the grid is present. Am I making sense? Here a part of my script... does any one know how to modify it when the element being referred to (eg Q14_r2_c1) is not present on the page? ie check if element exists - if so execute script...???

if((document.mainform["Q14_r1_c1"].value.length==0 && document.mainform["Q14_r2_c1"].value.length==0) && (document.mainform["Q14ns_r1_c1"].checked==false))
{
  strErrorMessage = "Please provide an answer in every column";
}


Thanks
Russell
asked Sep 13, 2012 by rapizel Bronze (1,420 points)
retagged Sep 13, 2012 by Walter Williams

1 Answer

0 votes
Use
[js]
if(document.mainform["Q14_r1_c1"])
{
if((document.mainform["Q14_r1_c1"].value.length==0 && document.mainform["Q14_r2_c1"].value.length==0) && (document.mainform["Q14ns_r1_c1"].checked==false))
{
  strErrorMessage = "Please provide an answer in every column";
}
}
the first part checks existence of Q14_r1_c1
answered Sep 13, 2012 by Bahadir Ozkurt Gold (16,910 points)
Thank you very much
...