469,311 Members | 2,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,311 developers. It's quick & easy.

Hide a DIV element based on dropdownlist selection

Good morning all,
Any ideas for an easy function to show/hide a DIV element? I have two drop
down lists on a page. I have two div elements I want to show and hide. If
you select "other" in dropdownlist 1 I want to show hidden DIV 1, or if the
user selects "other" in dropdownlist 2 I want to show hidden DIV 2. And
vice versa, if "other" is not selected, I want to show the relevant div. I
can do this with two different function, but i think I could combine this
into one function. I want to call this from either dropdown and pass itself
to the function, if the dropdownlist is dropdown1 I want to evaluate it and
hide/show DIV1, or if it's dropdown2, I want to show/hide DIV2. Any
suggestions? Thanks Everybody.

Regards,
Chris
Oct 26 '05 #1
1 5944
Chris Kettenbach wrote:
Good morning all,
Good evening.
Any ideas for an easy function to show/hide a DIV element?


Script:

function setStyleProperty(o, sProperty, value)
{
if (o)
{
if (typeof o.style != "undefined")
{
if (typeof o.style[sProperty] != "undefined")
{
return (o.style[sProperty] = value) == value;
}
}
// for NN4, positioned elements only
else if (typeof o[sProperty] != "undefined")
{
return (o[sProperty] = value) == value;
}
}

return false;
}

function show(o)
{
return setStyleProperty(o, "visibility", "");
}

function hide(o)
{
return setStyleProperty(o, "visibility", "hidden");
}

var ref = referenceToDivElement;
HTML:

<select ... onchange="(condition) ? show(ref) : hide(ref);">
BTW, I think that's a FAQ.
HTH

PointedEars
Oct 26 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Owen Funkhouser | last post: by
27 posts views Thread by Nicholas Couch | last post: by
3 posts views Thread by veganeater | last post: by
1 post views Thread by serge calderara | last post: by
5 posts views Thread by srampally | last post: by
11 posts views Thread by Santosh | last post: by
6 posts views Thread by Doogie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.