/    Sign up×
Community /Pin to ProfileBookmark

JQuery hide/ show depends on result of checkbox

On Initial loading of this webpage the div should be hidden in other words style=”display:none” along with all the checkboxes unchecked, so far so good. The checkbox when checked should show the div with id specifyOther which with what I have done so far works perfect but when the user unchecks the checkbox, the div should go back to its initial state of hidden which it doesn’t seem to do. I know I have to narrow down to this specific checkbox (hence the id) as there are others which shouldn’t be affected and not pasted here. I’m not to sure as to where I have made a fault even though its a simple little thing as reversing the checked state. This is the code as following:

<script type=”text/javascript” src=”jquery-latest.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){$(“#notspecified”).click(function(){if($(“#notspecified”).length == $(“#notspecified:checked”).length){$(“#specifyOther”).show();}else{$(“#specifyOther”).removeAttr(“show”);}
});
});
</script>

<input type=”checkbox” name=”natureOther” value=”other” id=”notspecified”/> Other <div id=”specifyOther” style=”display:none”><input type=”text” name=”txtsbOther” maxlength=”” size=”55″/></div>

any solutions, ideas, and corrections, and suggestions much appreciated

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nsathauthorApr 30.2012 — my bad I found out was wrong instead of the

else{$("#specifyOther").removeAttr("show");}

I just changed it code:

else{$("#specifyOther").hide();
×

Success!

Help @nsath spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...