Is it possible to hide a control until it is needed? Like a visible or hidden
property?

In particular I'm looking at a listbox and a button...

Could someone please post example code that does it?

Thanks a lot for your help.

Re: Hide controls until needed by OfficeGuyGoesWild

OfficeGuyGoesWild
Wed May 09 17:08:56 CDT 2007

On May 10, 2:21 am, XP <X...@discussions.microsoft.com> wrote:
> Is it possible to hide a control until it is needed? Like a visible or hidden
> property?
>
> In particular I'm looking at a listbox and a button...
>
> Could someone please post example code that does it?
>
> Thanks a lot for your help.

Here is a working example from a Money Management website I wrote and
use daily. The key is to specify a "span id" for the html elements,
and control the display of it using a script, where you toggle the
value to either "none" or "block" based on events in the page.

Regards.. Marty Lindsay
Editor
www.TheScriptLibrary.com


<html>
<head>
<title>Add Transactions</title>
</head>

<SCRIPT LANGUAGE="VBScript">
Sub UpdateDate
Form.Date.Value = DatePart("D",Now) & "/" & DatePart("M",Now) & "/" &
DatePart("YYYY",Now)
End Sub

Sub DisplayTransfer
Form.Account2.style.display = "block"
Prefix.Innerhtml="From Account"
ToPrefix.InnerHtml="To Account"
End Sub

Sub HideTransfer
Form.Account2.style.display = "none"
Prefix.Innerhtml="Account"
ToPrefix.InnerHtml=""
End Sub


</SCRIPT>

<body bgcolor="white" text="black" OnLoad = "UpdateDate">

<font face="arial" size = "2">
<table align=center><img src="\images\Logo.gif"></table>
<h4>
Add Transactions
</h4>
<hr>

<TABLE BORDER=0 cellspacing=1 cellpadding=1 WIDTH=700 ALIGN=CENTER>

<form name="form" method="post" action="add_to_Database.asp">

<tr>
<td width=150 valign=top align=left>
<p>Date</p>
</td>
<td width=350 valign=top align=left>
<p>
<input type="text" name="Date" size="12">
</p>
</td>
</tr>
<tr>
<td width=150 valign=top align=left>
<p>Payee</p>
</td>
<td width=350 valign=top align=left>
<p>
<input type="text" name="Payee" maxlength="50">
</p>
</td>
</tr>
<tr>
<td width=150 valign=top align=left>
<p>Amount</p>
</td>
<td width=350 valign=top align=left>
<p>
<input type="text" name="Amount" maxlength="12">
</p>
</td>
</tr>
<tr>
<td width=150 valign=top align=left>
<p>Category</p>
</td>
<td width=350 valign=top align=left>
<p>

<%
Dim adoCon 'Holds the Database Connection Object
Dim rsCategory 'Holds the recordset for the records in the database
Dim stCategory 'Holds the SQL query for the database

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("Database.mdb")
Set rsCategory = Server.CreateObject("ADODB.Recordset")
strCategory = "SELECT tblCategories.Category AS CategoryList FROM
tblCategories ORDER BY Category;"
rsCategory.Open strCategory, adoCon

Response.Write ("<select size=""1"" name=""Category"">")
Response.Write ("<option value=""""> </option>")

Do While not rsCategory.EOF

Response.Write ("<option value=" & """")
Response.Write (rsCategory("CategoryList"))
Response.Write ("""")
If rsCategory("CategoryList") = "Transfer" Then
Response.Write (" OnChange=""TransferSelect""")
End If
Response.Write (">")
Response.Write (rsCategory("CategoryList"))
Response.Write ("</option>")
rsCategory.MoveNext
Loop
Response.Write ("</select>")
rsCategory.Close
Set rsCategory = Nothing

%>


</p>
</td>
</tr>

<tr>
<td width=150 valign=top align=left>
<p>Type</p>
</td>
<td width=350 valign=top align=left>
<p>

Withdrawal<input type=radio name="TransactionType"
value="Withdrawal" OnClick="HideTransfer" checked>
<img src=\images\WhiteSpace.gif border="0">
Deposit<input type=radio name="TransactionType" value="Deposit"
OnClick="HideTransfer">
<img src=\images\WhiteSpace.gif border="0">
Transfer<input type=radio name="TransactionType" value="Transfer"
OnClick="DisplayTransfer">
</p>
</td>
</tr>

<tr>
<td width=150 valign=top align=left>
<p><span id="Prefix">Account</p>
</td>
<td width=350 valign=top align=left>
<p>
<%
Set rsAccount = Server.CreateObject("ADODB.Recordset")
strAccount = "SELECT tblAccountList.Account AS AccountList FROM
tblAccountList WHERE Open = True ORDER BY Account;"
rsAccount.Open strAccount, adoCon

Response.Write ("<select size=""1"" name=""Account1"">")
Response.Write ("<option value=""""> </option>")

Do While not rsAccount.EOF
If rsAccount("AccountList") = "Visa" Then
Response.Write ("<option selected value=" & "")
Else
Response.Write ("<option value=" & "")
End If
Response.Write (rsAccount("AccountList"))
Response.Write ("" & ">")
Response.Write (rsAccount("AccountList"))
Response.Write ("</option>")
rsAccount.MoveNext
Loop
Response.Write ("</select>")
rsAccount.Close


%>


</p>
</td>
</tr>


<tr>
<td width=150 valign=top align=left>
<p><span id="ToPrefix"></p>
</td>
<td width=350 valign=top align=left>
<p>
<%
rsAccount.Open strAccount, adoCon

Response.Write ("<select size=""1"" style=""display:none;""
name=""Account2"">")
Response.Write ("<option value=""""> </option>")

Do While not rsAccount.EOF
If rsAccount("AccountList") = "Visa" Then
Response.Write ("<option selected value=" & "")
Else
Response.Write ("<option value=" & "")
End If
Response.Write (rsAccount("AccountList"))
Response.Write ("" & ">")
Response.Write (rsAccount("AccountList"))
Response.Write ("</option>")
rsAccount.MoveNext
Loop
Response.Write ("</select>")
rsAccount.Close
Set rsAccount = Nothing

%>


</p>
</td>
</tr>
<tr>
<td>
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</form>
</TABLE>

<hr>

<!--#include file="Menu.asp"-->


</body>
</html>


Re: Hide controls until needed by Ayush

Ayush
Wed May 09 20:18:39 CDT 2007

[XP]s message :
> Is it possible to hide a control until it is needed? Like a visible or hidden
> property?
>
> In particular I'm looking at a listbox and a button...
>
> Could someone please post example code that does it?
>
> Thanks a lot for your help.


Yes. Use the display:none or Visibility:hidden CSS properties.

Untested code:

<div id="hideShow">
<select >
<option>...
...
</select>
<button ..>Something</button>
</div>
<button onclick="toggleDisplay">Hide/Show</button>

In toggleDisplay:
Sub toggleDisplay
If hideShow.style.display="none" Then
hideShow.style.display=""
Else
hideShow.style.display="none"
End If
End Sub

Good Luck, Ayush.
--
Scripting Solutions Center : http://snipurl.com/Scripting_Solutions

Re: Hide controls until needed by XP

XP
Wed May 09 21:11:00 CDT 2007

Hi Ayush,

Thanks for the reply; you've helped many times and I appreciate it;

I'm afraid your response is a little over my head; is there a chance you
could elaborate a bit more...?

Is your solution JScript? - is there a VBScript solution?

Thanks


"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [XP]s message :
> > Is it possible to hide a control until it is needed? Like a visible or hidden
> > property?
> >
> > In particular I'm looking at a listbox and a button...
> >
> > Could someone please post example code that does it?
> >
> > Thanks a lot for your help.
>
>
> Yes. Use the display:none or Visibility:hidden CSS properties.
>
> Untested code:
>
> <div id="hideShow">
> <select >
> <option>...
> ....
> </select>
> <button ..>Something</button>
> </div>
> <button onclick="toggleDisplay">Hide/Show</button>
>
> In toggleDisplay:
> Sub toggleDisplay
> If hideShow.style.display="none" Then
> hideShow.style.display=""
> Else
> hideShow.style.display="none"
> End If
> End Sub
>
> Good Luck, Ayush.
> --
> Scripting Solutions Center : http://snipurl.com/Scripting_Solutions
>

Re: Hide controls until needed by XP

XP
Wed May 09 21:31:00 CDT 2007

Hi Again Ayush, never mind - I got it using your model as posted; I'm just
dense...

Thanks again for your help!!!!!

"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [XP]s message :
> > Is it possible to hide a control until it is needed? Like a visible or hidden
> > property?
> >
> > In particular I'm looking at a listbox and a button...
> >
> > Could someone please post example code that does it?
> >
> > Thanks a lot for your help.
>
>
> Yes. Use the display:none or Visibility:hidden CSS properties.
>
> Untested code:
>
> <div id="hideShow">
> <select >
> <option>...
> ....
> </select>
> <button ..>Something</button>
> </div>
> <button onclick="toggleDisplay">Hide/Show</button>
>
> In toggleDisplay:
> Sub toggleDisplay
> If hideShow.style.display="none" Then
> hideShow.style.display=""
> Else
> hideShow.style.display="none"
> End If
> End Sub
>
> Good Luck, Ayush.
> --
> Scripting Solutions Center : http://snipurl.com/Scripting_Solutions
>

Re: Hide controls until needed by Ayush

Ayush
Thu May 10 01:53:42 CDT 2007

[XP]s message :
> Hi Again Ayush, never mind - I got it using your model as posted; I'm just
> dense...

> Thanks again for your help!!!!!

You are welcome!

Good Luck, Ayush.
--
Script Center : http://microsoft.com/technet/scriptcenter/default.mspx