this is a small but very annoying glitch in my form.
I have a flag that, when clicked, shows other flags and input fields for the user to add additional information. If this trigger flag is disabled, additional options disappear.
However (the plot thickens), if a different flag is set in the form, the trigger flag can be checked and additional parameters will appear , but if it is not set, the additional parameter will not disappear!
(Sorry it was a long time ago, but I wanted to be clear!)
Here is my simple jQuery code:
$(function() { var boxes = $('.obstruct-opt'); boxes.hide(); var ob = $('li.obstructionOptions').children().eq(0); ob.change(function() { if ($('$(this):checked').val()) { boxes.show(); } else { boxes.hide(); } }); });
I tried various ways of checking if the trigger is set or not, but any suggestions are welcome.
Edit HTML as requested: (although it is simplified since my ASP.Net relay generated it)
<ul> <li class="obstructionOptions"> <span> <input id="Obstruction" type="checkbox" name="Obstruction" /> <label for="Obstruction">Obstruction</label> </span> <span class="obstruct-opt"> <input id="WeatherProof" type="checkbox" name="WeatherProof"/> <label for="WeatherProof">WeatherProof</label> </span> <span class="obstruct-opt"> <input id="WeatherProofFlap" type="checkbox" name="WeatherProofFlap"/> </span> </li> <li class="obstruct-opt"> <span>Obstruction Notes</span> <textarea name="ObstructionNotes" rows="7" cols="50" id="ObstructionNotes"/> </li> </ul>
Hope this helps!
Update: replacing the if condition with
if ($(this).is(":checked")) {
It causes nothing, no visible or disappearing actions are visible. Thanks for the offer tho, maybe with my html you can understand why?
Update Well, after publishing my HTML, I realized that ASP.Net stitches me up! As you can see, I select the ob ob object as the first child, but the first child is a generated span! ASP has been wrapping my flags in runs all this time, and I never suspected! insightful!
I used this code at the end:
$('ul li.obstructionOptions span').children().eq(0).click(function() { if ($(this).is(":checked")) { boxes.show(); } else { boxes.hide(); } });
Thanks adamantium, as it solved prod perfectly!
The problem is solved!
Do not trust ASP.Net with my markup !!!