Javascript: if statements with multiple conditions

Avatar

Avatar

kelmoreskee02

Avatar

kelmoreskee02

kelmoreskee02

16-06-2011

Hello,

I am a javascript novice looking to write code that is somewhat over my head.  I have some understanding of if, else statements - and not much else.

My form is organized similar to this with radiobuttons:

1: Yes/No    A: t,u,v

2: Yes/No    B: w,x,y

3: Yes/No

I have been able to script so that if 1 is yes, A is visible.  Then choosing A=t, one row of a table appears; u, two rows; etc.  2 is similar, and 3 is just a yes/no to visualize some other fields, with no additional radiobuttons.

I also wanted to add a check box to view the entire form if checked.  But when unchecked, I also want the fields to continue to show up as dictated by the selections for 1, 2, 3, A, and B.

If this is possible, I need help organizing the if/else statements so that the javascript will run.  My thoughts was to do:

If viewall checkbox ==checked, all visible

else{

     if (1 == Yes) {

          if (A == null) { fields=visible/invisible}   

          if (A == t) { fields=visible/invisible}

          if (A == u) {fields=visible/invisible}

          ...

     }

     if (2 == Yes) {

          if (B == null) {fields=visible/invisible}

          if (B == w) {fields=visible/invisible}

          ...

     }

     if (3 == Yes) {fields=visible/invisible}

}

else{

     if (1 == No) {fields=visible/invisible}

     if (2 == No) {fields=visible/invisible}

     if (3 == No) {fields=visible/invisible}

}

else{

If (viewall checkbox == unchecked) {all invisible}

}

I must either have problems with my logic or have syntax issues because the code will not execute.  But if this works, then I believe I will also will run into the problem of executing commands for all of the different scenarios, ie if 1 is yes, 2 is yes, but 3 is no.  So I need some help on how to set up this script, and any other issues I may not recognize.

Let me know if you need any additional information.  Thanks for your help.

Thanks,

Kevin

View Entire Topic

Avatar

Avatar

MorisTM

Avatar

MorisTM

MorisTM

16-06-2011

If I understand properly, you need a way to know which sections to hide (those portions not filled in) when the View All option is deselected.

Maybe exactly when you deselect the View All option, you could interrogate all the fields to determine which sections to keep visible, and to on/off the corresponding radiobutton. This could result in alot of processing for this benefit.