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 7586613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:28:17+00:00 2026-05-30T19:28:17+00:00

On my jsp page I have a loop that loops elements in a collection,

  • 0

On my jsp page I have a loop that loops elements in a collection, which create dynamic fields. Each iteration creates a field type called editType and names it as editType1, editType2…

There are 3 possible options for editType. Based on what the user choosese for editType, I need to hide the irrelevant fields and only show the fields that pertain to the editType that they have chosen. For each editType option there is a cooresponding tbody named editTypeA, editTypeB and editTypeC. An example is if editType = A then tbody name EditTypeA should show and EditType B and EditTypeC should be hidden. Since the tbody for each edity type will be created each time in the loop, how can I have the jquery function display the appropriate tbody for just the clicked editType field and not for all the editType fields on the page.

The jsp page looks like:

 <c:forEach items="${surveyInfo.allSurveyEdits}" var="surveyEdits" varStatus="status">                              

            <tr class="altrow" align="left">
                <td height="19">Type:</td>
                <td width="17%" colspan="3">
                    <sf:select path="allSurveyEdits[${status.index}].editType" id="editType${status.count}" cssClass="inputbox-survey">
                        <sf:option value="" label="Select" />
                        <sf:option value="A" label="A" />
                        <sf:option value="B" label="B" />
                        <sf:option value="C" label="C" />               
                    </sf:select>                      
                </td>                   
            </tr>   

     <tbody id="editTypeA">

            <tr align="left">                      
                 <td>Edit Description:</td>
                 <td colspan="3">
                    <sf:select path="allSurveyEdits[${status.index}].editFormatDesc" id="editFormatDesc${status.count}" cssClass="inputbox-survey">
                        <sf:option value="" label="Select" />
                        <sf:option value="Data is entered in correct format" label="Data is entered in correct format" />
                        <sf:option value="Correct decimal precision is entered" label="Correct decimal precision is entered" /> 
                    </sf:select>
                 </td>
            </tr>


     </tbody>

     <tbody id="editTypeB">

            <tr align="left">
                <td>Edit Description:</td>
                <td colspan="3">                        
                     <sf:select path="allSurveyEdits[${status.index}].editRangeDesc" id="editRangeDesc${status.count}" cssClass="inputbox-survey">
                        <sf:option value="" label="Select" />
                        <sf:option value="PCT Diff" label="PCT Diff" />
                        <sf:option value="Defined Range" label="Defined Range" />   
                    </sf:select> 
                </td>
             </tr> 


  </tbody>

  <tbody id="editTypeC">

            <tr align="left">
                <td>Edit Description:</td>
                <td colspan="3">
                    <sf:select path="allSurveyEdits[${status.index}].editIntegrityDesc" id="editIntegrityDesc${status.count}" cssClass="inputbox-survey">
                        <sf:option value="" label="Select" />
                        <sf:option value="Required Field Validation" label="Required Field Validation" />
                        <sf:option value="Data Type Validation" label="Data Type Validation" /> 
                        <sf:option value="Calculation Validation" label="Calculation Validation" /> 
                    </sf:select>
                </td>
             </tr>

 </tbody>

 </c:forEach>   

The jquery function that I have come up with but works only if the page doesn’t have multiple items in the collection:

 $(document).ready(function() { 

         $("#editTypeA").hide(); 
         $("#editTypeB").hide(); 
         $("#editTypeC").hide(); 


         if($("#editType").find("option:selected").val() == "A") { 
                  $("#editTypeA").toggle(); 
              } 

         if($("#editType").find("option:selected").val() == "B") { 
                  $("#editTypeB").toggle(); 
              } 

         if($("#editType").find("option:selected").val() == "C") { 
                  $("#editTypeC").toggle(); 
              } 

         $("#editType").change(function() { 

              if($(this).find("option:selected").val() == "") { 
                  $("#editTypeA").hide(); 
                  $("#editTypeB").hide(); 
                  $("#editTypeC").hide(); 

              }

              if($(this).find("option:selected").val() == "A") { 
                  $("#editTypeA").toggle(); 
                  $("#editTypeB").hide(); 
                  $("#editTypeC").hide();   


                  $("#editTypeB").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 

                     $("#editTypeC").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 

                } 

              if($(this).find("option:selected").val() == "B") { 
                  $("#editTypeB").toggle(); 
                  $("#editTypeA").hide(); 
                  $("#editTypeC").hide(); 

                   $("#editTypeA").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 

                     $("#editTypeC").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 

              } 
              if($(this).find("option:selected").val() == "C") { 
                  $("#editTypeC").toggle(); 
                  $("#editTypeA").hide(); 
                  $("#editTypeB").hide(); 


                   $("#editTypeA").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 

                     $("#editTypeB").find(':input').each(function() { 
                    switch(this.type) { 
                        case 'select-multiple': 
                        case 'select-one': 
                        case 'text': 
                        case 'textarea': 
                            $(this).val(''); 
                            break; 
                        case 'checkbox': 
                        case 'radio': 
                            this.checked = false; 
                    } 
                    }); 
              }                               
           }); 





        }); 
  • 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-30T19:28:18+00:00Added an answer on May 30, 2026 at 7:28 pm

    I resolved this by making the tbody name to contain the name of the editType element, this enabled me to use *= selector to get elements that contained the name.

    Thanks for all the help.

     $('select[name*="editType"]').each(function (i) { 
    
    
            }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written jsp page in which i create String with gb2312 charset, Then
On a Jsp page I have some select elements which were disabled after a
I have a jsp page which should load a popup using ajax. The content
I have a JSP page, which accepts user strings in more than 23 languages.
I have a JSP page which accepts SQL queries, performs them then returns the
I have a functional JSP page that accepts URL parameters and updates a table
Right now I have a JSP page that allows to sort some items, when
I have a list of elements, each of them appeared in my page through
I have jsp page that contains <span class=requiredFieldsMessageAsterix>*</span> I use a jsp include to
I have a jsp page which contains the code which prints all files in

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.