• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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
0
lapucca
Asked:
lapucca
  • 3
  • 3
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now