By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,625 Members | 2,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,625 IT Pros & Developers. It's quick & easy.

VBScript/CSS problem (display property)

P: n/a

I'm having some trouble getting something to work. I'm not even sure
whether or not this is possible, but it *seems* like it should be.
I've done a fair amount of experimenting and googling...but maybe I'm
still missing something obvious...

I'm trying to have a <div> appear and disappear based on what a
switchbox is set to. Having <div style="display: none;"> and then
setting the display property to inline onChange works fine, but I
can't make it disappear again when I onChange back to another value.
I have tried this various ways (including having an invisible class
and changing the class rather than the display property directly) and
I can't figure out a way to have it appear when the switchbox is set
to one value, and disappear if the switchbox is set to another value.
I also can't use OnLoad to set the display property of the div to
none, it has to be set in the div tag itself...which is another reason
why I suspect I'm doing something wrong.

The visibility property is no good because I don't want the div to
take up space.

Here is an example page that doesn't work in any version of IE I have
tried it in (reformatted for USENET..sorry about the readability).
It's set up this way because I need to use the same function for
different switchboxes and <div>'s. This is for a massive form/table
so a separate function for each instance is no good. Any possible way
of getting the div to disappear and not take up space again after it
is made visible is welcome.

TIA

<html>
<head>
<script type="text/vbscript">
<!--
Sub DivChange (yesnobox, layername)
Dim strObjName
strObjName = "document.MainForm." & yesnobox & ".value"
If eval(strObjName) = "No" Then
document.getElementById(layername).style.display = inline
Elseif eval(strObjName) = "Yes" then
document.getElementById(layername).style.visibilit y = hidden
End If
End Sub
-->
</script>

</head>
<body>
<form name="mainform">
<select id="test" name="CD-ROM required" class="normal"
onChange="DivChange 'test', 'test1'">
<option selected>
<option value="Yes">Yes
<option value="No">No</select>
<div id="test1" style="display: none;">testtestesttest</div>
</form>
</html>
-- endus -- at -- endus -- dot -- com --
Not knowing what you want out of life is a pattern in itself,
perhaps the most rigid pattern of all. As a matter of fact
it's probably the most predominant pattern in the country
today, and just another name, in the long run, for what we
call the "American way of life". You are in a large and
very crowded boat, floating around aimlessly and complacently
in a very treacherous sea. At times I seriously regret that
I've divorced myself so completely from that pattern. Life
is much simpler that way, and very often much more pleasant.
-Hunter S. Thompson
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 07 Apr 2004 10:44:33 -0400, in
comp.infosystems.www.authoring.stylesheets endus <do**@email.invalid>
wrote:

change your script to:
------------------------------
<script type="text/vbscript">
<!--
Sub DivChange (yesnobox, layername)
Dim strObjName
strObjName = "document.MainForm." & yesnobox & ".value"
If eval(strObjName) = "No" Then
document.getElementById(layername).style.display = "block"
Elseif eval(strObjName) = "Yes" then
document.getElementById(layername).style.display = "none"
End If
End Sub
-->
</script>
------------------------------
---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 20 '05 #2

P: n/a
On Wed, 07 Apr 2004 16:04:41 GMT, Jeff North
<jn****@yourpantsbigpond.net.au> wrote:
On Wed, 07 Apr 2004 10:44:33 -0400, in
comp.infosystems.www.authoring.stylesheets endus <do**@email.invalid>
wrote:

change your script to:
------------------------------
<script type="text/vbscript">
<!--
Sub DivChange (yesnobox, layername)
Dim strObjName
strObjName = "document.MainForm." & yesnobox & ".value"
If eval(strObjName) = "No" Then
document.getElementById(layername).style.display = "block"
Elseif eval(strObjName) = "Yes" then
document.getElementById(layername).style.display = "none"
End If
End Sub
-->
</script>
------------------------------
---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------


You, my friend, are the MAN. Thanks so much for the quick reply.
Note to posterity: the double quotes around the none or block are
essential!

Woohoo, it finally works!

-- endus -- at -- endus -- dot -- com --
Not knowing what you want out of life is a pattern in itself,
perhaps the most rigid pattern of all. As a matter of fact
it's probably the most predominant pattern in the country
today, and just another name, in the long run, for what we
call the "American way of life". You are in a large and
very crowded boat, floating around aimlessly and complacently
in a very treacherous sea. At times I seriously regret that
I've divorced myself so completely from that pattern. Life
is much simpler that way, and very often much more pleasant.
-Hunter S. Thompson
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.