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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client vs. Server scripts.... Connecting to SQL Server Database

Status
Not open for further replies.

Chomauk

Programmer
Jun 8, 2001
130
I am attempting to create my first web site and I am becoming overwhelmed with ASP, VBScript, JavaScript, DHTML. I have been making great progress, however, I am at a point where I need to get some expert advice/suggestions.
First of all when would I want to run server side scripts and when would I want to run Client scripts.
Below is the current asp page I have created which works fine, however, where the <script language=vbscript> is located I can only use this as client(correct?). Is this the way it must be? I also have code to run on the server using <% %> but this doesn't work where I have <script Language = vbscript>. I tried <@% Language = VBScript %> but it doesn't work either and I don't get an error.
I also have a connection to my SQL Database and return a recordset successfully when running from the server. I have included a comment and a question in my code in UPPER CASE between the <script language=vbscript> and </script> tags. Any help/advice would be greatly appreciated.
I am running IIS using Windows 98.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;<html>
<style TYPE=&quot;text/css&quot;>
<!--
TABLE {
FONT-WEIGHT: normal;
FONT-SIZE: 24px;
COLOR: blue;
LINE-HEIGHT: 120%;
FONT-FAMILY: Verdana,Arial,sans-serif;
TEXT-DECORATION: none
}
.PickLeague{CURSOR:hand}
-->
</style>

<head>

<SCRIPT language=VBScript>
'THIS ONLY WORKS AS A CLIENT SCRIPT.
sub selectLeague_OnClick()
With document.LeagueList.selectLeague
.disabled = true

Dim intCount
With document.all.SelectTeam.Options
for intCount = 0 to .length
.Remove(intCount) ' REMOVE CURRENT LIST
Next
End With

' I'LL WANT TO CONNECT TO THE DATABASE AGAIN AND RETURN A RECORDSET TO LOAD INTO THE SELECT BOX.
' THE BELOW CODE (LOCATED BETWEEN <% AND %>) TO CONNECT TO SQL DOES NOT WORK HERE. WHY IS THAT?
' HOW COULD I MAKE IT SO I DON'T HAVE TO REUSE THE SAME CODE IN THE SAME PAGE? THE BELOW CODE WAS WRITTEN TO VERIFY THAT I COULD RECIEVE THE SELECTED TEXT OF THE FIRST SELECT BOX.

Dim oOption
set oOption = document.createElement(&quot;OPTION&quot;)
oOption.text=.Options(.selectedIndex).Text
document.all.SelectTeam.add(oOption)
set oOption = Nothing

.disabled = false
End With
end sub
</SCRIPT>


</head>

<body style=&quot;color:blue&quot; bgcolor=&quot;Gainsboro&quot;>

<p>
<pre>
<font size=&quot;5&quot; face=&quot;Times, serif&quot; color=&quot;green&quot;>
Welcome to Dawg Pounders Fantasy Football Draft Site...
</font>
<font size=&quot;3&quot; face=&quot;Times, serif&quot; color=&quot;purple&quot;>
Still under construction but making great progress!!!
</font>

<%
Response.Write &quot;<form name='LeagueList'>&quot;

dim rs
dim strConn

set rs=server.CreateObject(&quot;adodb.recordset&quot;)

rs.CursorLocation=3 'clientside
rs.CursorType=3 'staticrecordset
rs.PageSize=100

strConn=&quot;Provider=SQLOLEDB;Persist Security Info=False;&quot; & _
&quot;User ID=sa;Initial Catalog=FantasyFootball2001;&quot; & _
&quot;Initial File Name=C:\MSSQL7\Data\FantasyFootball2001_Data.MDF&quot;

rs.Open &quot;GetLeagueNames&quot;,strConn

rs.movefirst

Response.Write &quot;<table>&quot;
Response.Write &quot;<tr>&quot;
Response.Write &quot;<td>&quot;

Response.Write &quot;<fieldset style='width: 180'>&quot;
Response.Write &quot;<Legend style='font-size:12pt'> Select league </Legend>&quot;
'Response.Write &quot;<font size='2' face='Times, serif'>&quot;
'Response.Write &quot;Select League Name&quot;
'Response.Write &quot;</font>&quot;

Response.Write &quot;<select style='width: 175; font-size:16pt' Name='selectLeague' size='10'&quot;
Response.Write &quot;<option> </option>&quot;
Do While Not rs.EOF
Response.Write &quot;<option>&quot; & rs(&quot;League&quot;) & &quot;</option>&quot;
rs.MoveNext
Loop

rs.Close
Set rs =nothing

Response.Write &quot;</select>&quot;
Response.Write &quot;</fieldset&quot;
Response.Write &quot;</td>&quot;

Response.Write &quot;<td width='50'>&quot;
Response.Write &quot;</td>&quot;

Response.Write &quot;<td>&quot;
Response.Write &quot;<fieldset style='width: 180'>&quot;
Response.Write &quot;<Legend style='font-size:12pt'> Select Team </Legend>&quot;
Response.Write &quot;<select id='idSelectTeam' style='width: 175; font-size:12pt' Name='selectTeam' size='10'&quot;
Response.Write &quot;<option> </option>&quot;
Response.Write &quot;</select>&quot;
Response.Write &quot;</fieldset&quot;
Response.Write &quot;</td>&quot;
Response.Write &quot;</tr>&quot;
Response.Write &quot;</table>&quot;

Response.Write &quot;</form>&quot;

%>

<A style=&quot;color:red&quot; HREF=&quot;News.asp&quot;>Main Test Page</A>

<A style=&quot;color:red&quot; HREF=&quot;Login.asp&quot;>Login Test Page</A>


</body>

</html>
 
Chomauk,

First, when sending strings to the browser, try using fewer &quot;response.writes&quot;. For instance,

Response.Write &quot;<table>&quot;
Response.Write &quot;<tr>&quot;
Response.Write &quot;<td>&quot;


Should be:
Response.Write &quot;&quot;<table><tr><td>&quot;

This uses less network trips to your browser.
Also, you are missing &quot;>&quot; in fieldset.

Also, I believe, the drop down &quot;SELECT&quot; uses &quot;onchange&quot;, not &quot;onclick&quot;.

Fengshui1998

 
Thanks for the help, Fengshui1998.
I made the changes you suggested concerning the Response.Write and the missing &quot;>&quot; and it works, however, I still can't get the select second select box to get filled for onclick or onchange. The routine is called but if I put RUNAT=&quot;SERVER&quot;, it won't work. I also tried it without the quotes. Do you know what the reason for this may be?
 
The reason is that once the page is displayed, there is no more communication with the server unless you do a post. Putting runat=server does nothing to help you here; that code is only accessible when the page is initially loading and it can't access or respond to any of the html elements that are on the page. So, the main point here is once the page is loaded, all stuff you do is running on the client's machine and the webserver doesn't know you exist anymore (the browser is no longer connected to the web server).

All that being said, there are two solutions available for you that I can think of:

1) Either put a hidden frame on your page or use an IFRAME (I think you can use IFRAMES to do this) and have this frame's source be a form page. When the onclick event occurs on your select element, you'd communicate with the hidden frame and tell it to submit your request (e.g. do a post). It would return the html for a select element that contains the option elements that you want to have in your other select box. So, then you'd communicate with the hidden frame again and grab the &quot;data&quot; from it to populate your select box. I've never done this myself, but it do know that it can be done.

2) If your users will all be running IE (MS), they have MDAC version 2.1 or greater installed on their machine and their security settings allow activeX controls, you can use Remote Data Services (RDS). It's relatively easy to use and allows communications with objects on the server from the client without the page having to be posted. Sorry I don't have a link in mind to point you to, but doing a search on RDS will get you there.

Regards,
Glenn
 
GlennBSI,
Thanks very much for taking the time to answer my problem. I probably won't be able to use iform since some people in my draft use AOL. Currently looking for work arounds but your advice is right on....

Thanks again, it's much apprecitated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top