Solved

Hiding/Unhiding HTML objects with VBScript

Posted on 2009-07-07
8
689 Views
Last Modified: 2012-05-07
Hello,

I'm trying to hide/unhide certain objects based on a condition.  My hiding works, but my unhiding doesn't, can anyone see why?

I've successfuly tested my conditions and element names.  The only thing that fails is .visibility = "visable"
<script language="VBScript">
 
'hideCondition = "True" or "False"
 
If hideCondition = "True" Then
 
frm.elements("cboF" & fID & "V" & vID).style.visibility = "hidden" 'WORKS
 
Else
frm.elements("cboF" & fID & "V" & vID).style.visibility = "visible" 'DOESN'T WORK
 
end If
 
</script>

Open in new window

0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:Chad Haney
ID: 24797600
Seems like it is not an issue with the visibility code you have.  Just double checked to make sure that is the correct VBscript format.

Your hideCondition looks like it must not ever be evaluating to false.

Here is the example code I used to test it.
<html>
<head>
 
</head>
<body>
<form>
<input type="text" id="cboF1" name="cboF1" value="1"/>
<input type="text" id="cboF2" name="cboF2" value="2"/>
</form>
<script language="VBScript">
 
set el =document.getElementById("cboF1")
el.style.visibility = "hidden"
el.style.visibility = "visible"
set el =document.getElementById("cboF2")
el.style.visibility = "hidden"
 
</script>
</body>
</html>

Open in new window

0
 

Author Comment

by:APD_Toronto
ID: 24797700
No, I thought the same thing, that my False condition is not being reached, but I have a msgbox() in both conditions, and they are firing.
I am including my entire script, it may be little had to get the whole picture, but I think the key point is that both message boxes are popping up.
 

		<script language="VBScript">
		
			fCount = CInt(frm.elements("txtFCount").value)
			strFIDs = frm.elements("txtFIDs").value
					
		
			For f = 1 To fCount
				fID = Left(strFIDs, InStr(1, strFIDs, ",") - 1)
				strFIDs = Mid(strFIDs, Instr(1, strFIDs, ",") + 1, Len(strFIDs) - Instr(1, strFIDs, ",") + 1) 
				
				v=0
				
				depStatus = frm.elements("txtFStat" & fID).value
				'msgbox("stat=" & depStatus)
				If depStatus = "True" Then 
			
					vCount = CInt(frm.elements("txtVCount").value)
					strVIDs = frm.elements("txtVIDs").value	
					For v = 1 To vCount
						vID = Left(strVIDs, InStr(1, strVIDs, ",") - 1)
						strVIDs = Mid(strVIDs, Instr(1, strVIDs, ",") + 1, Len(strVIDs) - Instr(1, strVIDs, ",") + 1) 
				
						frm.elements("cboF" & fID & "V" & vID).style.visibility = "hidden"
						msgbox("hidden cboF" & fID & "V" & vID)
					Next 'vendor
					
				ElseIf depStatus = "False" Then 
			
					vCount = CInt(frm.elements("txtVCount").value)
					strVIDs = frm.elements("txtVIDs").value	
					For v = 1 To vCount
						vID = Left(strVIDs, InStr(1, strVIDs, ",") - 1)
						strVIDs = Mid(strVIDs, Instr(1, strVIDs, ",") + 1, Len(strVIDs) - Instr(1, strVIDs, ",") + 1) 
						
						el = frm.elements("cboF" & fID & "V" & vID)
						el.style.visibility = "visible"
						msgbox("visible cboF" & fID & "V" & vID)
					Next 'vendor
					
				End If
			
			Next 'flight
</script>

Open in new window

0
 

Author Comment

by:APD_Toronto
ID: 24825743
The correct syntax was:
frm.elements("cboF" & fID & "V" & vID).style.display = "none"
 
 
frm.elements("cboF" & fID & "V" & vID).style.display = "block"

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Chad Haney
ID: 24826486
display is actually a different css attirbute than visibility.  VBscript is able to adjust both attributes.

Display none will remove the placement of the item, visibility will hide the item, but the space is still reserved.
0
 

Author Comment

by:APD_Toronto
ID: 24826584
The bottom line is that visibility failed to work
0
 
LVL 12

Accepted Solution

by:
Chad Haney earned 500 total points
ID: 24826798
What browser is it failing on?  If it's anything except for IE you want it used for I would recommend changing over to javascript.

The code snippet I have above demonstrates it being functional on IE, hiding both then showing the first only.
0
 

Author Closing Comment

by:APD_Toronto
ID: 31600748
I awarded you points.  Happy?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write 1 row of data from Excel to a txt file 10 35
Text too large in Chrome 17 63
Why is my $_POST not going to results page 10 41
Validating number not work with decimal 4 27
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question