Solved

jQuery -- monitor "onchange" event for dropdownlist

Posted on 2013-02-06
11
681 Views
Last Modified: 2013-02-16
Using jQuery, how do I monitor the "onchange" event for one or more dropdownlist controls?

What I want to do is if all the dropdownlist controls have text = "Denied" I want to SHOW a <div> that was hidden before.
0
Comment
Question by:knowlton
11 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 38862629
0
 
LVL 5

Author Comment

by:knowlton
ID: 38864667
This code is working, but the div I am trying to show won't show.  Nothing happens when I call "show(  )":



<script type="text/javascript">


    $(document).ready(function () {
            
        var howmanybidstatusdropdowns = $('select[id*="ddlStatus"]').size();
        var currentcount = 0;
            
        //alert(howmanybidstatusdropdowns);
        
        $('select[id*="ddlStatus"]').change(function () {
            
            var countoffound = 0;
            
            $('select[id*="ddlStatus"] option:selected').each(function () {
            
                if ($(this).text() == "Denied") {
            
                    countoffound = countoffound + 1;
                    currentcount = countoffound;            
                }
            });

            if (countoffound == howmanybidstatusdropdowns) {
                alert(countoffound + ' were found');                
            }
        });

        if (currentcount == howmanybidstatusdropdowns) {
            alert(countoffound + ' were found');


            //THE ALERT FIRES, BUT THIS LINE OF CODE DOES NOTHING...
            $('div[id*="divNewBids"]').show();
        }


    });
                                  
</script>

Open in new window

0
 
LVL 5

Author Comment

by:knowlton
ID: 38864707
That code was wrong above.  The other alert was firing, not the one that I intended.


Here is the updated code:

<script type="text/javascript">


    $(document).ready(function () {

        var howmanybidstatusdropdowns = $('select[id*="ddlStatus"]').size();
        var currentcount = 0;

        //alert(howmanybidstatusdropdowns);

        $('select[id*="ddlStatus"]').change(function () {

            var countoffound = 0;

            $('select[id*="ddlStatus"] option:selected').each(function () {

                if ($(this).text() == "Denied") {

                    countoffound = countoffound + 1;
                    currentcount = countoffound;
                }
            });


            if (currentcount == howmanybidstatusdropdowns) {
              
              //THIS ALERT STILL FIRES 
              alert(countoffound + ' were found');


            //THIS DOES NOTHING...
               $('div[id*="divNewBids"]').show();
            }

        });


        alert('outside');

    });

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38870819
@knowlton:  I am not a jQuery expert and don't really have time to research this, but I can see from just reading the question and the code example, that it is very incomplete.  So I would like to offer a suggestion that will help you get a better answer.  Follow the excellent guidance of the SSCCE.  With a valid SSCCE, we would see the HTML document as well as the jQuery statements, and it would be packaged into something we could copy, paste and run on our own servers.  If you frame a question with that little extra bit of detail you will get good answers very quickly.

You might also ask a moderator to add this question to the JavaScript and HTML Zones.  You can have up to five Zones for any question and I am sure some experts in those two additional Zones would be able to help.

Best of luck with it, ~Ray
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 29

Expert Comment

by:fibo
ID: 38870921
not a jQuery expert either.

But looking at the code, I would think that
       $('div[id*="divNewBids"]').show();
would probably need something to handle the * which implies that the selection might have several items. So, without knowing too much about jQuery I would first test
       $('div[id*="divNewBids"]').each.show();
or
       $('div[id*="divNewBids"]').each(show());
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 100 total points
ID: 38871076
          //THIS DOES NOTHING...
               $('div[id*="divNewBids"]').show();

That mean the selector is wrong
mean you don't have div like this one :
 <div id="fflldkfdlkfdivNewBidslslfkskfslk">....</div>

so nothing to show
are you sure it's an ID attribute and not a class?
So you need to use a << . >> instead << # >>

Could you paste the HTML/CF?/ASP.NET? code for this div and only for this div (not your full page)?
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 400 total points
ID: 38872371
To work show(), the visiblity state of the div should be style="display:none".

I think you have put visibilty hidden. try with display none.

OR

are you want to display one div or a set of divs with the ids like divNewBids.

If it one is div, do not use like operator (*).

just $('#divNewBids').show() is enough.

and also check divNewBids is a class name or id name.

if it is a class, use $('.divNewBids').show() for single.

$('div[class*="divNewBids"]').show(); for multiple.
0
 
LVL 5

Assisted Solution

by:knowlton
knowlton earned 0 total points
ID: 38876536
This code below is now working fine.  I think the problem was I had some invalid statements in the <div> I was trying to show(  ).


<script type="text/javascript">


    $(document).ready(function () {

        var howmanybidstatusdropdowns = $('select[id*="ddlStatus"]').size();
        var currentcount = 0;

        //alert(howmanybidstatusdropdowns);

        $('select[id*="ddlStatus"]').change(function () {

            var countoffound = 0;

            $('select[id*="ddlStatus"] option:selected').each(function () {

                if ($(this).text() == "Denied") {

                    countoffound = countoffound + 1;
                    currentcount = countoffound;
                }
            });


            if (currentcount == howmanybidstatusdropdowns) {    
                $('div[id*="divNewBids"]').css('width', 'auto');
                $('div[id*="divNewBids"]').css('height', 'auto');
                $('div[id*="divNewBids"]').css('visibility', 'visible');              
            }

        });
    });
                                      
</script>

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 38896155
Thanks everyone.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now