I'm new at javascript and jquery and have used this site (and others) to try and figure out why the click function in the fiddle below does not properly work.
When you run the code, you'll see a checkbox and textarea, even when the checkbox is not selected. The correct behavior should be; only show the textarea when the checkbox is selected. I'm sure i'm missing something simple here.
Any help is much appreciated.
HTML:
<input type="checkbox" id="OtherAdv" name="OtherAdv" value="1" data-mini="true" /><label for = "OtherAdv">Other?</label>
<textarea rows="4" cols="50" class="formfont_small" id="OtherAdvDiag" name="OtherAdvDiag" data-mini="" placeholder="Please list others"></textarea>
Javascript:
$(document).ready(function () {
$('#OtherAdv').click(function () {
var $foo = $(this);
if ($foo.is(':checked')) {
$('#OtherAdvDiag').show();
} else {
$('#OtherAdvDiag').hide();
}
});
});
$('#OtherAdvDiag').hide();before your click function would seem to do what you want.