/    Sign up×
Community /Pin to ProfileBookmark

select box + show/hide content

I have a form where I have a dropdown box with values of yes(default selected) and no. What I want to do is if a user selects ‘yes’, then show an input box. ff they select ‘no’, then show a textarea to allow them to enter content. How can I do this?

Thanks

to post a comment
HTML

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisMar 15.2007 — <html>
<head>
<script type="text/javascript">
function showhide(sel) {
if (sel.options[sel.selectedIndex].value == "no")
{sel.form.t1.style.display = "none";}
if (sel.options[sel.selectedIndex].value == "yes")
{sel.form.t1.style.display = "block";}
}
</script>
</head>
<body>
<form onsubmit="return false">
<select onchange="showhide(this)">
<option value="yes" defaultSelected>yes
<option value="no">no
</select>
<br>
<input type="text" name="t1" style="display: block">
</form>
</body>
</html>
Copy linkTweet thisAlerts:
@jrthor2authorMar 15.2007 — ok, just by looking at the code, I'm not sure this is exaclty what I want. My form elements are in a table, so when I select 'yes', I want to to show an input box, if I select 'no' I want to show a textarea (not an input box).

Also, my for is in a table with 2 columns, so I want to show a particular row if they select yes (which has a label and an input box), or show a row with a textarea that spans 2 columns.).

Also, when the page loads up, I don't want the input box or textarea to show at all.

will this script do that?
Copy linkTweet thisAlerts:
@gil_davisMar 16.2007 — will this script do that?[/quote]No.
Copy linkTweet thisAlerts:
@jrthor2authorMar 16.2007 — Can this be done, that's what I'm looking for.
×

Success!

Help @jrthor2 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...