Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Make ListBox Appear BEFORE HTML Table, Not After Table 1

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
Hi ASP experts,

The first time the page loads, a listbox is displayed at the top of the page - nothing else.

After the user makes a selection from the listbox, an SQL statement selects the rows, then a ASP sub is called to build the table rows using response.write statements

*****************************
...The problem is the table pushes the listbox to the bottom of the page, after the end of the table.
Sometimes the table is pretty long so the user has to scroll all the way to the end to make another selection from the listbox.

How can I force the table to be placed after the listbox rather than before it ?

I hope I have described my question clearly enough.
Using ASP and HTML.

Thanks for your ideas. John


 
All you need to do is either write the table out after you have written the listbox, or write the listbox before you write the table (same thing really). HTML is processed in the same order it is written and is generally displayed this way as well. Without code I cannot help any further.
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thanks for taking the time to reply Tarwn !

"...or write the listbox before you write the table (same thing really)."

Actually that's what I'm doing... and the listbox gets pushed down to after the table rows.

I build the listbox outside of the sub. Because when the page first displays, just want them to see the listbox.
If I build the listbox inside the sub that builds the table... they will initially see a blank form.

Can I force the table to position in a certain section of the page... leaving the listbox intact ?
Thanks, John
 
Call the sub to display the table after you write the listbox, that way the table will get written after the list box does and will display afterwards. If doesn't sem like it will fit your problem, show me a little of your code and I'll see if I can't find a more specific solution.
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thanks again Tarwyn,

This is the entire code for this ASP...

My objectives are to:
- Display the listbox (populated) and the footer menu links
- Then if a phone ext is selected from the list...
display :
-'Calls From Extension abcd'
-'Number of Calls listed: 999'
-The ext listbox
-followed by the table rows showing all the phone calls for the extension the user selected
-followed by the footer menu links

All this works fine... except that, after a n ext is selected... the listbox gets moved to AFTER the table rows

As you can see...the onChange="Ext.submit()" resubmits the page. Is that the problem ?

Thanks for any help, John






<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<% Option Explicit %>

<!--John Bates October 2002-->

<!--#include file=&quot;adovbs.inc&quot;-->
<!--#include file=&quot;Connect.asp&quot;-->


<%
Dim OrigExt, CallDesc, CalledNo, CallingNo, CallDate, DurHH, DurMM, DurSS, AuthCode
Dim i
Dim rs
Dim sql
Dim selectExt,newExt
Dim intRecs
Dim blnFirstTime
Dim blnTimeout


blnTimeout = False

blnFirstTime = True

'Set Timeout limit it is SECONDS

server.ScriptTimeout = 120
%>

<%
'Select the call records, build the recordset

SelectData(selectExt)

sub DisplayTable

If blnTimeout = True Then

Response.Write &quot;<H2><B>Timeout occurred - too many records selected - please change selection criteria to select less data<BR></H2></B>&quot;

End If


Response.Write &quot;<H2><B>Calls From Phone Extension: &quot; & selectExt & &quot;</H2></B>&quot;
Response.Write &quot;<H4><B>Number of Calls Listed: &quot; & intRecs & &quot;</H4></B>&quot;

response.write &quot;<TABLE cellspacing=2 border=1 align=center>&quot;
' Build column headings
response.write &quot;<tr>&quot;

response.write &quot;<td><B>Ext</B></TD>&quot;
response.write &quot;<td><B>Description</B></TD>&quot;
response.write &quot;<td><B>No. Called</B></TD>&quot;
response.write &quot;<td><B>Calling No.</B></TD>&quot;
response.write &quot;<td><B>Date of Call</B></TD>&quot;
response.write &quot;<td><B>Hours</B></TD>&quot;
response.write &quot;<td><B>Mins</B></TD>&quot;
response.write &quot;<td><B>Secs</B></TD>&quot;
response.write &quot;<td><B>Auth Code</B></TD>&quot;

response.write &quot;</tr>&quot;

' Read thru recordset and write the table rows
DO WHILE NOT rs.eof
' put fields into variables



OrigExt=rs(&quot;OrigExt&quot;)
CallDesc=rs(&quot;RecDesc&quot;)
CalledNo=rs(&quot;CalledNo&quot;)
CallingNo=rs(&quot;CallingNo&quot;)
CallDate=rs(&quot;CallDate&quot;)
DurHH=rs(&quot;DurHH&quot;)
DurMM=rs(&quot;DurMM&quot;)
DurSS=rs(&quot;DurSS&quot;)
AuthCode=rs(&quot;AuthCode&quot;)


' write the fields to browser table
response.write &quot;<tr>&quot;

response.write &quot;<td>&quot;
response.write rs(&quot;OrigExt&quot;) & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write CallDesc & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write CalledNo & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write CallingNo & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write CallDate & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write DurHH & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write DurMM & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write DurSS & &quot;<br>&quot;
response.write &quot;</td>&quot;

response.write &quot;<td>&quot;
response.write AuthCode & &quot;<br>&quot;
response.write &quot;</td>&quot;


response.write &quot;</tr>&quot;
rs.movenext
LOOP


rs.Close
Set rs=Nothing

response.write &quot;</TABLE>&quot;

blnFirstTime = False

End Sub


sub SelectData(selectExt)


sql = &quot;SELECT OrigExt, RecDesc, CalledNo, CallingNo, CallDate, DurHH, DurMM, DurSs, AuthCode FROM Calls WHERE OrigExt = '&quot; & selectExt & &quot;' ORDER BY CallDate&quot;

set rs = createobject(&quot;adodb.recordset&quot;)

On error resume next
rs.open sql,conn, adOpenStatic, adLockReadOnly, adCmdText


If err <> 0 Then

If instr(err.description) = &quot;ASP 0113&quot; Then

blnTimeout = True


End If

End If

intRecs = rs.RecordCount

End Sub

%>


<HTML>
<HEAD>
<TITLE>Phone Calls for Selected Extension - EHP Springfield</TITLE>

<style type=&quot;text/css&quot;>
h2
{
font-family: Arial;
color:#990033;
}

TD
{
font-weight: bold;
}

</style>

</HEAD>

<body bgcolor=&quot;#FFFFFF&quot;>
<FORM NAME=&quot;Ext&quot;>
<CENTER>

<%

'Set a default extension to display as web page is initialized

selectExt = &quot;9999&quot;

'Check value of EXT, the dropdown box, to see if user has requested a different phone extension
newExt = Request(&quot;EXT&quot;)
If newExt <> &quot;&quot; Then
selectExt = newExt

End If


'Call the sub to select call data for the requested extension

If selectExt <> &quot;9999&quot; Then

SelectData(selectExt)


DisplayTable

End If

blnFirstTime = False

%>


<%

'Build the dropdown box entries from the extension in Extensions table


sql = &quot;SELECT Ext FROM Extensions WHERE Ext > 0 ORDER BY Ext&quot;

set rs = createobject(&quot;adodb.recordset&quot;)

rs.open sql,conn, adOpenStatic, adLockReadOnly, adCmdText

%>

<BR>
<SELECT NAME=&quot;EXT&quot; size=&quot;1&quot; onChange=&quot;Ext.submit()&quot;>
<option>Select an Extension #</option>

'add all the phone extensions to the dropdown listbox
<%
Do While NOT rs.eof
%>

<option value=&quot;<%=rs.Fields(&quot;Ext&quot;)%>&quot;>
<%=rs.Fields(&quot;Ext&quot;)%>
</option>

<%

rs.MoveNext()

Loop

%>
'... end of section that build the dropdown box entries

</SELECT>


</CENTER>

<BR>
<CENTER><TABLE CELLSPACING=&quot;0&quot; CELLPADDING=&quot;2&quot; BORDER=&quot;2&quot;>
<TR>
<TD><FONT SIZE=+0><FONT COLOR=&quot;#999999&quot;>
<A HREF=&quot;PhoneLogMenu.html&quot;
onMouseOver=&quot;window.status = 'Return to the Phone Call menu';
return(true)&quot;>Return to Phone Log menu</A></FONT></FONT></TD>
<TD><FONT COLOR=&quot;#999999&quot;><FONT SIZE=+0>
<A HREF=&quot;CallsByExt.asp&quot;
onMouseOver=&quot;window.status = 'Display Phone Calls by Ext';
return(true)&quot;>Display Phone Calls by Ext</A></FONT></FONT></TD>
<TD><FONT COLOR=&quot;#999999&quot;><FONT SIZE=+0>
<A HREF=&quot;faqs.html&quot;
onMouseOver=&quot;window.status = 'Frequently Asked Questions';
return(true)&quot;>F.A.Q.s</A></FONT></FONT></TD>
</TR>
</TABLE>


</FORM>
</BODY>
</HTML>

<%

rs.close
conn.close
Set rs = nothing
set conn = nothing

%>
 
Here is the form with my changes. I moved the function call down to below the listbox, the function itself can be placed anywhere in the script, I generally prefer to keep it seperate from any code that is being executed outside of function calls, but that is probably a java programming influence. Anyways, here is the altered form:
Code:
<FORM NAME=&quot;Ext&quot;>
<CENTER>

<% 

'Set a default extension to display as web page is initialized

selectExt = &quot;9999&quot;

'Check value of EXT, the dropdown box, to see if user has requested a different phone extension 
newExt = Request(&quot;EXT&quot;)
If newExt <> &quot;&quot; Then
    selectExt = newExt

End If


'####################### Note: Change ###################################
'### This is being called before the listbox is created,it has been moved

'Call the sub to select call data for the requested extension

'If selectExt <> &quot;9999&quot; Then

'SelectData(selectExt)

'DisplayTable
'########################################################################

End If

blnFirstTime = False

%>


<%

'Build the dropdown box entries from the extension in Extensions table


sql = &quot;SELECT Ext FROM Extensions WHERE Ext > 0 ORDER BY Ext&quot;

set rs = createobject(&quot;adodb.recordset&quot;)

rs.open sql,conn, adOpenStatic, adLockReadOnly, adCmdText

%>

<BR>
<SELECT NAME=&quot;EXT&quot; size=&quot;1&quot; onChange=&quot;Ext.submit()&quot;>
<option>Select an Extension #</option>

'add all the phone extensions to the dropdown listbox
<%
Do While NOT rs.eof
%>

<option value=&quot;<%=rs.Fields(&quot;Ext&quot;)%>&quot;>
<%=rs.Fields(&quot;Ext&quot;)%>
</option>

<%

rs.MoveNext()

Loop

%> 
'... end of section that build the dropdown box entries

</SELECT>
<br>
<%
'####################### Note: Addition ########################
'This section was moved from above
'Call the sub to select call data for the requested extension

If selectExt <> &quot;9999&quot; Then

SelectData(selectExt)

DisplayTable
'###############################################################
%>

</CENTER>

<BR>
<CENTER><TABLE  CELLSPACING=&quot;0&quot; CELLPADDING=&quot;2&quot; BORDER=&quot;2&quot;>
<TR>
<TD><FONT SIZE=+0><FONT COLOR=&quot;#999999&quot;>
<A HREF=&quot;PhoneLogMenu.html&quot;
onMouseOver=&quot;window.status = 'Return to the Phone Call menu';
return(true)&quot;>Return to Phone Log menu</A></FONT></FONT></TD>
<TD><FONT COLOR=&quot;#999999&quot;><FONT SIZE=+0>
<A HREF=&quot;CallsByExt.asp&quot;
onMouseOver=&quot;window.status = 'Display Phone Calls by Ext';
return(true)&quot;>Display Phone Calls by Ext</A></FONT></FONT></TD>
<TD><FONT COLOR=&quot;#999999&quot;><FONT SIZE=+0>
<A HREF=&quot;faqs.html&quot;
onMouseOver=&quot;window.status = 'Frequently Asked Questions';
return(true)&quot;>F.A.Q.s</A></FONT></FONT></TD>
</TR>
</TABLE>


</FORM>

Hope that helps, also you may want to check if it is necessary to call the SelectData twice in every run. You call it once before your table sub and then again once before you make the call to your table sub, I think this may just be duplicating efforts rather than giving you valid feedback, I believe you don't need the first call above your table function declaration.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Wow, thanks for your help Tarwn !

Now the listbox is only at the top...
and I removed the other call to SeelctData - still works and the page loads faster now.

Really appreciate your ideas. John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top