lapucca
asked on
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.
AddNewPatient.aspx
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();
}
});
MasterPage.masterAddNewPatient.aspx
ASKER
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
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()
Thank you.
AddNewPatient.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
Can you explain what this line of code is doing?
$('#<%=lsAPExerciseOptions .ClientID% >:selected ').each(fu nction(i, selected) {
if (parseInt($(selected).val( )) == 11)
What about that 'i'? What is it? Thank you.
$('#<%=lsAPExerciseOptions
if (parseInt($(selected).val(
What about that 'i'? What is it? Thank you.
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.
"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.
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.