The label and textbox isn't displaye when the last select option is selected

Hi, I'm using asp.net, C# and jQuery
The script below in the content page is not working.  I tried debugging it in Firebug in FF and it seems that the value==11 was never found even when the last option selected (other) carries a value of 11.  This script used to work before the code was split to Content page.  Thank you.
$('#<%=lsAPExerciseOptions.ClientID%>').click(function() {

                var found = false;
                $('#<%=lsAPExerciseOptions.ClientID%>:selected').each(function(i, selected) {
                    if (parseInt($(selected).val()) == 11) {
                        found = true;
                    }
                });

                if (found) {

                    $('#<%=lbOtherExercise.ClientID%>').show();
                    $('#<%=txtOtherExercise.ClientID%>').show();
                }
                else {

                    $('#<%=lbOtherExercise.ClientID%>').hide();
                    $('#<%=txtOtherExercise.ClientID%>').hide();
                }

            });

Open in new window

MasterPage.master
AddNewPatient.aspx
lapuccaAsked:
Who is Participating?
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Regarding "==="... that's a common mistake people make with JavaScript. I used to also until I attended a local User Group meeting where it was the featured topic.

1. "=" Sets the left side of the expression equal to the right side.

2. "==" First checks to see if the left and right side of the expression are of the same type; if they are not the same type, it will make them the same (I don't know what the pecking order is) and then compares to see if the left and right side are the same.

3. "===" Compares the left and right side of the expression and determines if they are the same.

<<< What about this part of the text, parseInt($(selected).val(), would that need changing since it's now in the Content page? >>>

No, it wouldn't. JavaScript only acts upon the rendered HTML, so moving that to a Content page shouldn't make any difference.

Are you sure that the paths to your script files (lines 9-11) are still correct?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
One thing I see immediately is that your "==11" should be "===11". Do this regardless of the suggestion below.

If it works as soon as you change it back to a regular web form with no content areas then all that has happened is the control id the JavaScript is looking for has shifted.

Look at the rendered HTML to make sure what is being spit out to the JavaScript actually is what you intended.
0
 
lapuccaAuthor Commented:
Control id is not a problem.  I attached the Page view source code in the attached file.  I set breakpoints inside that javascript and it is running through it.  However, the "found" var stays false.  
also, why 3 equal sign?  Are your sure?  It was always working before when it's just 2 equal signs.  Also, that's the syntax I remember because it's the same in C#.

What about this part of the text, parseInt($(selected).val(), would that need changing since it's now in the Content page?  
Thank you.
AddNewPatient.aspx
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
lapuccaAuthor Commented:
Well, I think the path would be correct.  Only that part of the script that's posted is not working.  The other part of the script, the dietoption part the label and textbox are hiding and showing correctly.  Also, I see in the Firebug that it's stepping through that part of the code except the var found stays false.
0
 
lapuccaAuthor Commented:
Can you explain what this line of code is doing?
 $('#<%=lsAPExerciseOptions.ClientID%>:selected').each(function(i, selected) {
                    if (parseInt($(selected).val()) == 11)

What about that 'i'?  What is it?  Thank you.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
For control lsAPExerciseOptions, go through each choice and check to see if it is checked. If so, is the value equal to 11.

"i" in this case is specified parameter of a custom function... Which is based on prior knowledge that this HTML input object has child objects, and that a property they share is a boolean value which represents whether or not that object has been checked.

Whoever wrote that function knew the DOM well enough to know that that could iterate over that collection of child controls.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.