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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:55:54+00:00 2026-06-02T12:55:54+00:00

Can some spot what I am doing wrong in the code below please? I

  • 0

Can some spot what I am doing wrong in the code below please? I know it’s not the most elegant code, but I am doing five things at the moment and thought I could knock this easy one out quickly to get it off my plate.

All I want to do is>> if project type selected equals a particular value, show a fieldset, if it does not equal that value, hide the fieldset. Pretty simple right? I can’t get the fieldset to hide if the value selected does not match.

Mind you, I am new to jquery, but this is a basic if/else – what am I doing wrong here? Thank you in advance.

$('fieldset#section-841', 'fieldset#section-837' ).hide();
var DM_projtype = new Array(
        {value : 'Direct Mail', sect_id : 'fieldset#section-841'},
        {value : 'Multiple items', sect_id : 'fieldset#section-837'}
    );
$('select#3596').change(function() {
    var getDM_projType = $(this).val();
    var sect_id = '';
     for (var i = 0; i < DM_projtype.length; ++i) 
        {
            if (DM_projtype[i].value == "Direct Mail" )
                {
                    sect_id = DM_projtype[i].sect_id;
                   $(sect_id).show();
                }
            else
                {
                   $('fieldset#section-841').hide(); 
                }
            if (DM_projtype[i].value == "Multiple items" )
                {
                    sect_id = DM_projtype[i].sect_id;
                   $(sect_id).show();
                }
            else
                {
                   $('fieldset#section-837').hide(); 
                }
       }
  });
  • 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-06-02T12:55:57+00:00Added an answer on June 2, 2026 at 12:55 pm

    You have structured your code against logic it seems – each element of your array is going to be processed through the loop, so you execute both an if and else of each block set you contain. You should instead do this:

    $('select#3596').on('change', function() // do .change() if using a lower jQuery version
    {
        var thisVal = $(this).val(); // Assuming this returns 'Direct Mail' or 'Multiple Items'
    
        $(DM_projtype).each(function()
        {
             $(this.sect_id).hide();
    
             if(this.value == thisVal)
                $(this.sect_id).show();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably doing something stupid, but I can't spot it. I've installed Eclipse Helios
For some reason I can't spot, redirect in codeigniter is not working. I'm getting
For some reason my Telerik MVC Editor() is not working. Can anyone spot what
I am having some trouble creating a nested association and I can't quite spot
Can some one help me, I have heard alot of things and I dont
Can some one please explain, what does SVN branch, tag, merge do? Why they
Can some one please guide me to understand which jar file i need to
For some reason, my jQuery isn't working properly, and I can't spot the mistake,
My autocomplete is not working and I can't spot the error. Jquery : <script>
I've been arguing for some time against embedding server-side tags in JavaScript code, but

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.