add this to your css:
#url,#file{display:none;}
Main Topics
Browse All TopicsHey guys,
There are different varience of this question posted previously but none of the solutions have helped me(most of them were to get a radio button or check box to work)
I'm having a little trouble getting a drop down list selection to hide and show other DIVs in jquery. Can anyone help me with the code. The problem is something like this:
<select name="field_data_loc[key]"
<option value="didnotchoose" selected="selected">Choose
<option value="web">Website/URL</o
<option value="file">File to upload</option>
</select>
<div id="url">
....
</div>
<div id= "file">
...
</div>
So when someone selects "website" or "file to upload" it will show one and hide other. Thanks for any help provided.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html
<html>
<head>
<title>Script Demo Gops®</title>
<style>
body, table,input, select,span{font-family:ve
#url,#file{display:none;ba
</style>
<script language="javascript">
function showHide(o){
var u=document.getElementById(
var f=document.getElementById(
u.style.display=o=="web"?"
f.style.display=o=="file"?
}
</script>
</head>
<body>
<select onchange="showHide(this.va
<option value="didnotchoose" selected="selected">Choose
<option value="web">Website/URL</o
<option value="file">File to upload</option>
</select>
<div id="url">
URL
</div>
<div id= "file">
File
</div>
</body>
</html>
Here you go. If you are using jQuery.
No need for ifs to check each element wether its hidden or not and no need for styles. jQuery does it all for you.
<select name="field_data_loc[key]"
<option value="didnotchoose" selected="selected">Choose
<option value="web">Website/URL</o
<option value="file">File to upload</option>
</select>
<div id="url">
url
</div>
<div id= "file">
file
</div>
<div id= "web">
web
</div>
<SCRIPT LANGUAGE=javascript src="jquery.js"></script>
<script language="javascript">
function showHide(obj)
{
var showDiv = "#"+obj;
$("div").hide();
$(showDiv).show();
}
</script>
Business Accounts
Answer for Membership
by: TNamePosted on 2007-10-28 at 01:34:59ID: 20164026
Hi, try this:
4/strict.d td"> alue; ile').styl e.display= ''; rl').style .display=' none'; ile').styl e.display= 'none'; rl').style .display=' ';
class="form-select required" id="edit-field-data-loc-ke y" onChange="showHide(this)"> </option> ption>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html
<html>
<head>
<style>
div { border:1px solid #ddd; height:200px; width:400px; }
</style>
<script>
function showHide(obj) {
var s=obj[obj.selectedIndex].v
if (s=='file') {
document.getElementById('f
document.getElementById('u
}
else
if (s=='web') {
document.getElementById('f
document.getElementById('u
}
}
</script>
</head>
<body>
<select name="field_data_loc[key]"
<option value="didnotchoose" selected="selected">Choose
<option value="web">Website/URL</o
<option value="file">File to upload</option>
</select>
<div id="url">
url
</div>
<div id= "file">
file
</div>
</body>
</body>
</html>