APD Toronto
asked on
Hiding/Unhiding HTML objects with VBScript
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"
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>
ASKER
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.
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>
ASKER
The correct syntax was:
frm.elements("cboF" & fID & "V" & vID).style.display = "none"
frm.elements("cboF" & fID & "V" & vID).style.display = "block"
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.
Display none will remove the placement of the item, visibility will hide the item, but the space is still reserved.
ASKER
The bottom line is that visibility failed to work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I awarded you points. Happy?
Your hideCondition looks like it must not ever be evaluating to false.
Here is the example code I used to test it.
Open in new window