/    Sign up×
Community /Pin to ProfileBookmark

Showing fields based off of selection?

Hi all,

I have a php based form that is pretty simple. It has a select list with some dynamic options and a few other fields. I want to be able to have certain fields initially hidden, then show when a couple different options are selected from the dynamic list.

For example, the list may include
Option 1
Option 2
Option 3
Option 4

And if 2 or 4 are selected, these other form fields should show up. Is there any way to do this with javascript? Below is a snip of the simple form.

[code]
//Our dynamic select list.
echo “<select name=”options”>”;
for ($e=0; $e<$Option_Count; $e++) {
$option_id = $Options->option_id[$e];
$option_name = $Options->option_name[$e];

echo “<option name=’options’ value=’$option_id’>$option_name</option>”;

}
echo “</select>”;

//These should be hidden and only show when certain options are selected
echo “Item 1:<input type=”checkbox” name=”item1″>”;
echo “Item 2:<input type=”checkbox” name=”item2″>”;
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzJul 21.2005 — [url=http://www.dynamicsitesolutions.com/javascript/select_option_show_textbox/]Sounds like you want something like this.[/url]
×

Success!

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