[AccessD] OT-ASP OnChange To Call A Function

DWUTKA at marlow.com DWUTKA at marlow.com
Fri May 14 11:30:35 CDT 2004


Paul, this is a GCE. Gross Conceptual Error. <grin>.  A combobox is
something that your end user sees, on your website.  The ASP code you have
below 'creates' that combo box, and sends it to the user.  Everything you
put in ASP runs on the server, before the user gets the information.
(Technically speaking you can 'push' completed page information out to the
user, as more ASP code is running, but the end result is that the user
doesn't actually get anything you put into ASP).

So, how do you script for what you are doing?  You have to use Client Side
scripting, either VBScript, or JScript (or anything else that floats your
boat).  If you are not actually trying to do anything on the user's browser,
with the selected value, but instead, are just trying to retrieve it when a
user submits the selection, then you would use request.querystring or
request.form on the page that receives the submitted data.

This issue is probably one of the most common stumbling blocks between
switching from VB/Access development, to asp/web development.  In Access/VB,
there is a continuous 'flow' between the FE and BE.  In asp/web development,
you are dealing with a disconnected Front End.  Almost like taking a
snapshot of an Access form, then sending it to your client to fill out.
They fill it out, and send it back.  In the meantime, you just get to
twiddle your thumbs.  This has both advantages and disadvantages.  One
advantage is it immensely increases the number of 'concurrent' users in a
system, because you are truly doing a 'hit and run' on the database.  It
also makes on the fly development a lot easier, because you can change
anything you want, to a live system, and when you make a change, the next
person to get their 'copy' just gets the new version.  The biggest
disadvantage is there is no easy way to tell what a user is actually doing,
until they 'trigger' something that posts information back to you.

To answer your actual question, however, I think you would need this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBSCRIPT">
Function OfficeSelected
	msgbox ddOffices.options(ddOffices.selectedindex).text
End Function
</SCRIPT>
</HEAD>
<%
dim cnn
dim rs
dim strSQL
set cnn=server.createobject("ADODB.Connection")
set rs=server.createobject("ADODB.Recordset")
cnn.Provider="Microsoft.Jet.OLEDB.4.0"
cnn.Open "D:\edlevin.mdb"
strSQL="SELECT Name FROM Stores ORDER BY Name"
rs.Open strSQL, cnn, 1,1
If rs.EOF=False then rs.movefirst
%>
<BODY>
<SELECT Name='ddOffices' OnChange='OfficeSelected()'>
<OPTION Selected=""Selected"" Value="""">Choose....</OPTION>
                                    
<% Do Until rs.EOF=True%>
            <OPTION><%=rs.Fields(0).value%></OPTION>
<%
rs.MoveNext
loop
%>
 </SELECT>
</BODY>
</HTML>

It does what you ask of it.  A couple things to note.  in the function, I am
getting the .text property, instead of .value.  In HTML, an option within a
select object (ie, a line in a combo or listbox) can have a value different
then what is displayed in the box itself.

Drew


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of
paul.hartland at fsmail.net
Sent: Friday, May 14, 2004 10:27 AM
To: accessd
Subject: [AccessD] OT-ASP OnChange To Call A Function


To all,
 
I'm a bit new to ASP/HTML and currently working with dropdown boxes, however
I'm a bit confused on how to pass the selected text to a function.  My code
snippet for the dropdown box and function are below:
 
response.write "<DEFANGED_SELECT Name='ddOffices'
OnChange='OfficeSelected(this.selectedindex.text)'>"
response.write "<DEFANGED_OPTION Selected=""Selected""
Value="""">Choose....</DEFANGED_OPTION>"
                                    
While Not rsData.EOF
            response.write "<DEFANGED_OPTION>" & rsData.Fields("OfficeName")
& "</DEFANGED_OPTION>"
            rsData.MoveNext
Wend
 
<%
            ' Function just to display name of the office selected.
            Function OfficeSelected(strSelectedOffice)
                        response.write strSelectedOffice
            End Function
%>
 
The problem occurs when I select an item from the dropdown box, I get the
following error:
 
this.selectedindex.text Is Null or not an object
 
Can anyone point me in the right direction on what I'm doing wrong.
 
Thanks in advance for any help on this.
 
Paul Hartland

-- 

Whatever you Wanadoo:
http://www.wanadoo.co.uk/time/

This email has been checked for most known viruses - find out more at:
http://www.wanadoo.co.uk/help/id/7098.htm
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list