Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:14+00:00 2026-05-26T02:40:14+00:00

Although this is a form created in Breezingforms for Joomla, my question is more

  • 0

Although this is a form created in Breezingforms for Joomla, my question is more of a generic javascript question. I am very new to javascript so hopefully someone can answer this easily. This is being called upon initialization of a form.

I am using a javascript loop in a selection list object to hide/unhide various sections of a form, depending on the selection list choice. I’m trying to make the if/else if statements less clumsy. I’m sure there is a way to make this shorter and more concise, but being such a novice, I haven’t been able to figure it out.

On a side note (not as important at the moment, but it will be), I’d like to use this script for other selection list calls, with minor variations. I still am not too clear on reusing code. If someone has any comments on that, it would be appreciated.

BTW, I am even more of a novice at jQuery, so if you go there, be VERY kind! 🙂

var selListVal = "";
var selListInput =  JQuery("[name=\"mySelectionList[]\"]");
for (var i = 0; i < selListInput.length; i++)
 if (selListInput[i].value) {
  if (selListVal != "") selListVal += ",";
   selListVal += selListInput[i].value;
 }
    if( selListVal == "myselection01" ){
      ToggleFields('on', 'section', 'mysection01A', DeactivateField);
      ToggleFields('on', 'section', 'mysection01B', DeactivateField);
      } 
    else if( selListVal == "myselection02" ){
      ToggleFields('on', 'section', 'mysection01A', DeactivateField);
      ToggleFields('on', 'section', 'mysection01B', DeactivateField); 
      ToggleFields('on', 'section', 'mysection02A', DeactivateField);
      ToggleFields('on', 'section', 'mysection02B', DeactivateField);
      }
    else if( selListVal == "myselection03" ){
      ToggleFields('on', 'section', 'mysection01A', DeactivateField);
      ToggleFields('on', 'section', 'mysection01B', DeactivateField);
      ToggleFields('on', 'section', 'mysection02A', DeactivateField);
      ToggleFields('on', 'section', 'mysection02B', DeactivateField);
      ToggleFields('on', 'section', 'mysection03A', DeactivateField);
      ToggleFields('on', 'section', 'mysection03B', DeactivateField);
      }
     else {
      ToggleFields('off', 'section', 'mysection01A', DeactivateField);
      ToggleFields('off', 'section', 'mysection01B', DeactivateField);
      ToggleFields('off', 'section', 'mysection02A', DeactivateField);
      ToggleFields('off', 'section', 'mysection02B', DeactivateField);
      ToggleFields('off', 'section', 'mysection03A', DeactivateField);
      ToggleFields('off', 'section', 'mysection03B', DeactivateField);
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:40:15+00:00Added an answer on May 26, 2026 at 2:40 am

    How about something like this?

    var num = parseInt(selListVal.replace('myselection', ''));
    
    if(num > 0){
        ToggleFields('on', 'section', 'mysection01A', DeactivateField);
        ToggleFields('on', 'section', 'mysection01B', DeactivateField);
    }
    if(num > 1){
        ToggleFields('on', 'section', 'mysection02A', DeactivateField);
        ToggleFields('on', 'section', 'mysection02B', DeactivateField);
    }
    if(num > 2){
        ToggleFields('on', 'section', 'mysection03A', DeactivateField);
        ToggleFields('on', 'section', 'mysection03B', DeactivateField);
    }
    

    or to illustrate the idea by user968951

    var num = parseInt(selListVal.replace('myselection', ''));
    
    for (var x=1; x<=num; x++){
        ToggleFields('on', 'section', 'mysection0' + x + 'A', DeactivateField);
        ToggleFields('on', 'section', 'mysection0' + x + 'B', DeactivateField);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although this question and this question are close to what I'm asking, I believe
This is a follow on from my previous question although this is about something
I have a HashMap (although I guess this question applies to other collections) of
I'm working with ExpertPDF's Html-to-PDF conversion utility for this question (although I'm open to
My SQL knowledge is very limited, specially about SQLite, although I believe this is
I have a form which instances a new form that I've already created using
This is probably a stupidly simple question, but I'm stuck. I had created a
I am very new to this javascipt, jquery world and I am having great
I realize that this is probably a very basic question, but I have spent
Although this is FAQ i still couldn't find a suitable solution. I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.