select values--posting to mdb (beginner, asp) 
Author Message
 select values--posting to mdb (beginner, asp)

I've tried, lord knows, I've tried... if anyone could show me what I'm
doing wrong with this script it just might save the rest of my hair.

The idea is embarrassingly simple, much like my knowledge of ASP:  to
ask the user to choose an option from the select box, and store that
option, along with the date, in an access database.  The ODBC connection
has been verified:  the script works when I put constants in the
VALUES(), but I can't for the life of me get the script to read the
form.  As you can see, I'm trying to make it so that the user doesn't
have to click a submit button.. after they make the choice, they just
see the window disappear, and return to the parent document.  

Oh yeah, since the successful testruns with the constant values, I have
made the following changes(reasons):

Made the script into a SUB and called it with the onChange handler
(previously had onChange=submit() but without SUB-bing the script, it
would automatically run on loading and insert info into the .mdb whether
the form was completed or not.

..er, well that's the only change I've made.  Currently when I load the
page, when I change the selected value in the form, I get an "Object
Expected" javascript error (?) on the line containing the <select>.. I'm
nearly at my wit's end.

I hope I explained this clearly enough.. if you have the answer, please
explain it to me like I'm a 6-year-old.. : )  don't be afraid of
insulting my intelligence.

<!-begin dysfunctional script -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">


<%

        Dim conn
        Dim SourceAnswer
        Dim SqlStr

        sub ReadMe()

        SourceAnswer =
request.form("theform.source[theform.source.selectedindex].value")
        SqlStr = "INSERT INTO results (Answer,AnswerDate) Values('" &
SourceAnswer & "','01/01/99')"

        Set conn = Server.CreateObject("ADODB.Connection")
        conn.Open "FILEDSN=SourcePollResults.dsn"
        conn.Execute SqlStr
        Set conn = Nothing
        end sub

%>

<HTML>
<HEAD>
        <TITLE>Lens Express wants to know:</TITLE>
</HEAD>

<BODY BACKGROUND='images/back.jpg'>
<center>
<FORM method="post" action="sourcepoll.asp" name="theform">
<table width="100%" height="100%">
<tr><td align="center" valign="middle">
<select name="source" size="1" onChange="ReadMe(), window.close(self)">
<option selected value="no answer">How did you hear about us?</option>
<option value="Search Engine">Search Engine</option>
<option value="Banner Ad">Banner Ad</option>
<option value="tv">Television Ad</option>
<option value="print">Print Ad</option>
<option value="brochure">Brochure</option>
<option value="refer">Referral</option>
</select></td>
</tr>
</table>
</FORM>
</center>
</BODY>
</HTML>



Mon, 23 Jul 2001 03:00:00 GMT  
 select values--posting to mdb (beginner, asp)

Quote:
> SourceAnswer =
>request.form("theform.source[theform.source.selectedindex].value")
> SqlStr = "INSERT INTO results (Answer,AnswerDate) Values('" &
>SourceAnswer & "','01/01/99')"

Errr, the problem is that you are trying using DHTML syntax within the
Request headers. This doesn't work!

The way to do it is, for example (inside "sourcepoll.asp"):

<%
If (Request.Form("source").Count > 0) Then

    SourceAnswer = Request.Form("source")

    SqlStr = "INSERT INTO results (Answer,AnswerDate) Values('" & _
        SourceAnswer & "','01/01/99')"

Else
    Response.Write "Error - no option selected"
End If
%>

This checks to see if there really was a value selected. If so, it will run
the SQL; otherwise, it will return a page with the error message. The value
returned is the 'value' attribute of the option that was selected. For
example, if the user selected "Television Ad" then the SQL will write the
value "tv" to the database.

Also, the onChange property of your <select> is wrong. Try this, although I
don't think it works if you include the window closing code:

<FORM method="post" action="sourcepoll.asp" name="theform">
<table width="100%" height="100%">
<tr><td align="center" valign="middle">
<select name="source" size="1" onChange="VBScript: SubmitForm">
<option selected value="no answer">How did you hear about us?</option>
<option value="Search Engine">Search Engine</option>
<option value="Banner Ad">Banner Ad</option>
<option value="tv">Television Ad</option>
<option value="print">Print Ad</option>
<option value="brochure">Brochure</option>
<option value="refer">Referral</option>
</select></td>
</tr>
</table>
</FORM>

<script type="text/vbscript">
Sub SubmitForm()
    document.theform.submit()

    ' Don't know if this works:
    ' self.close()
End Sub
</script>

Peter

--
Peter Torr, Developer / Webmaster, Vantage Systems Australia.



Tue, 24 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. re-post: vbscript & mdb database : error

2. Posting values retrieved through VBscript to an .asp page

3. Passing SELECT values to ASP

4. Passing SELECT Values to ASP

5. Please Help - Passing SELECT values to ASP

6. Copy data from MDB on LAN to MDB on web server

7. Making a value selected in a select box.

8. How to select values from group of select lists

9. Cetting A Report To Select Records Based Upon A Value Selected In A Combo Box

10. 2nd post, Copy an MDB file!

11. ASP, vbscript, Access mdb and dates !

12. JScript/JavaScirpt to access .mdb data under ASP???

 

 
Powered by phpBB® Forum Software