how to use jquery to hide or show label and textbox dep on a listbox selection?

Hi, I'm using asp.net 3.5 and C#
lbOtherExercise, listbox, allows multiple selection.  If one of the selected value is 11 then I would like to show the label and textbox otherwise, hide them.  Attached are my code.  Thank you.
ManageAccounts.aspx
lapuccaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
@lapucca: could you please share a HTML only version of your problem?
0
lapuccaAuthor Commented:
Yeah, that is a good idea.  Thanks.
htmlCode.htm
0
Gurvinder Pal SinghCommented:
which specific textboxes do you want to show or hide based on listbox selections?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

lapuccaAuthor Commented:
the control's id lbOtherExercise and txtOtherExercise.  Thank you.
0
Gurvinder Pal SinghCommented:
add this into your document ready event handler

                  $("#lsAPExerciseOptions").change(function(){
                        if ( parseInt($(this).val()) >= 11 )
                        {
                              $("lbOtherExercise").show();
                              $("#txtOtherExercise").show();
                        }
                        else
                        {
                              $("lbOtherExercise").hide();
                              $("#txtOtherExercise").hide();
                        }
                  });
0
khan_webguruCommented:
I think above code will not work with multi selection as well as if you will directly click on last "Exercise" value first time before selecting any thing else it will not work but not sure. I download your code and tried to implement this.

One this you already apply onchange method on this multi seletion that was postback the page to stop this I remove the onchange="" from your code.

TO GET YOUR DESIRE RESULT

Please copy paste this code in ready method means right after this line

 
$(document).ready(function () {

Open in new window


Add this piece of code

 
$("#lsAPExerciseOptions").click(function () {

                var realvalues = [];
                var textvalues = [];
                var found = false;
                $('#lsAPExerciseOptions :selected').each(function (i, selected) {
                    if (parseInt($(selected).val()) == 11) {
                        found = true;
                    }
                });

                if (found) {
                   
                    $("lbOtherExercise").show();
                    $("#txtOtherExercise").show();
                }
                else {

                    $("lbOtherExercise").hide();
                    $("#txtOtherExercise").hide();
                }

            });

Open in new window


In this code on selection I looked into all selected values if value will be 11 then that will show text box other wise that will hide that.

If you want to hide this textbox on page load time then just add this line in ready method

 
$("#txtOtherExercise").hide();

Open in new window


Hope this will help you.

Regards,

Asif Ahmed Khan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lapuccaAuthor Commented:
Khan, you're correct.  I tried that code and exactly as you described.  Your script does work with multi-select.  Thank you both.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.