/    Sign up×
Community /Pin to ProfileBookmark

Making a form choice dissapear

I am trying to make a <div> containing certain choices not show unless a certain other checkbox is chosen. I have this for the checkbox:

[CODE]<input type=”checkbox” onclick=”hideAll(1);” />[/CODE]

And this is the div that I want to not show unless the above is checked:

[CODE]
<div class=”secondLevel” id=”tb”>
Enter name:
<input type=”text” />
</div>
[/CODE]

And here is the javascript:

[CODE]
function hideAll (val) {
if (val==”1″)
{
document.getElementById(‘tb’).style.display=’block’;
} else {
document.getElementById(‘tb’).style.display=’none’;
}
return true;
}
[/CODE]

I am not very familiar with JS so I apologize if I have made a simple mistake and I appreciate any guidance.

Thanks,

Todd

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@leupiauthorJan 22.2009 — Thanks for the information. The examples are very close to what I am looking for but I am having trouble tweaking them to work

The example that I am using is this one.

In this example when the 'yes' radio button us chosen the options appear, when the 'no' radio button is chosen, the option do not display. I have a check box and when checked I want the options to display, when left unchecked I do not want the options to display. I assume that I would need to set up an if/else but I am having trouble getting it to work.

What I have so far is this for the javascript (taken from the example):

[CODE]
function toggleMe(obj, a){
var e=document.getElementById(a);
if(!e)return true;
e.style.display="block"
return true;
}

function toggleMe2(obj, a){
var e=document.getElementById(a);
if(!e)return true;
e.style.display="none"
return true;
}
[/CODE]


and this is the HTML:

[CODE]
<input type="checkbox" onclick="return toggleMe(this, 'species')" />
Species Name<br />
<div class="secondLevel" id="species" style="display: none;">
Enter species name:
<input type="text" />
</div>
[/CODE]


I assume that I need to get rid of the second function in the JS and use that as the else statement; I have tried to do that in various ways but so far it is not working. Any help is appreciated.

Thanks,

Todd
×

Success!

Help @leupi 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.18,
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,
)...