Using ASP to make personalized survey Board

Source: Internet
Author: User
Tags modify odbc servervariables
Now, on the Internet to do a survey is very common, many commercial Web sites often have a variety of theme of the survey Board, some commercial sites are free to provide users with research boards, such as: Broad (poll.bodachina.com). Because of the popularity of the network, online surveys tend to achieve better results. In their own personal site to put a fun problem investigation board, indeed for the site Tim a lot of, and through the results of the survey you can more accurately understand the views of users on their site. As a webmaster, if your site also needs to investigate a topic, and you hate to use someone else's free board (free often comes at a price, such as advertising!). , then I suggest you take more than 10 minutes to read this article about using ASP to make a survey board. All you have to do is copy the code from the text to your machine and make a little change, and you immediately have a personalized survey board that belongs to you. All right, get up and look down.
The survey board has three files: Displays survey questions (research.html), handles user selection (select.asp), and browses survey results (viewresult.asp). The design idea is: The ASP obtains by the form the information, and accordingly modifies the record investigation obtains the ticket number the database, then the ASP reads the database, obtains each survey question the number of votes, passes the number of votes to adjust the corresponding bar chart display the width to be intuitive proportional to give the survey result. At the key point of the program, I have given a more detailed comment, here is no longer the basic knowledge of ASP. Readers can go to the Tao Bar ASP column to check. Of course, I would like you to debug the program on your own server, there is no understanding of the place, or check the side of the ASP technology Manual, look at the object, method or function of the detailed syntax to try to modify, see how the results change-this is a good way to learn programming.

I. Display of survey questions (research.html)

Survey problem design to be based on the actual situation, or pay attention to practicality or interesting, the style displayed on the Web page or simple or lively, this example is the author on the home page on the "21st century the most important thing?" "Interesting survey, to illustrate the problem, the following code omitted the beautifully decorated code, you can use the design of the table and other techniques to beautify the display of investigation problems. In order to submit or browse the survey without affecting the current page, the program is given a popup new window scheme.
Researchindex.html:

< HTML >
< title > Survey Board Test </title >
< head >
<!--start: Defining a newly opened window-->
< script Language=javascript >
<!--
var NewWindow = null
function Openwindow (Htmurl)
{
if (! NewWindow | | newwindow.closed)
{
NewWindow =
window.open (Htmurl, "Newwin", "toolbar=no,resizable=no,scrollbars=no,width=400,height=280");
}else
{
Newwindow.focus ();
}
}
-->
</script >
<!--end: Defining a newly opened window-->
< BODY >
<!--Start: Survey topics, Options->
< p > What do you think is the most important thing in 21st century? </p >
< form method= "POST" action= "vote/select.asp" name= "It" language= "JavaScript"
target= "Newwin" >
< P align= "left" >
< br >
< input type= "Radio" value= "1" name= "Options" > Knowledge (Knowledge is Power) < br >
< input type= "Radio" value= "2" name= "Options" > Education (Education Society does not end) < br >
< input type= "Radio" value= "3" name= "Options" > Money (Economy is Foundation) < br >
< input type= "Radio" value= "4" name= "Options" > Love (Love never Goes to the grave) < br >
< input type= "Radio" value= "5" name= "Options" > Ideals (God, what is the ideal) < br >
< input type= "Radio" value= "6" name= "Options" > Democratic Consciousness (Care politics) < br >
< input type= "Radio" value= "7" name= "Options" > Scientific ideas (Rejuvenating the country) < br >
< input type= "submit" value= "submitted" name= "voting" >
< input type= "button" value= "View" name= "Viewing" >
</form >
<!--Start: Survey topics, Options->
</body >

Second, the Processing user choice (select.asp)

Based on the above survey options, we draw the design of the database Researchdb.mdb that records the survey's votes (in Access, for example), and the table is named: Research. If your database and tables do not exist in the above name, then in the following procedures and operations, you should not forget to modify the corresponding.

Research on the table that holds poll numbers:

Field name data type default value
ID Auto Number 1
Select1 number 0
Select2 number 0
SELECT3 number 0
SELECT4 number 0
SELECT5 number 0
SELECT6 number 0
SELECT7 number 0


After the database has been built, we will set up a data source on the server. First, run ODBC in Control Panel, select System DSN, press the Add button, choose Microsoft Access Driver, press Finish when selected, and then enter the database name in the data Source name input box in ODBC settings. In this case, RESEARCHDB, and then press the Select button to select the database file (you do not say you forget the database you just designed is there), select and press "OK", you can see the new data source researchdb. In this way, we can call it in ASP.
Select.asp:

<%
' The following if statement determines whether the user has made a choice by verifying that the selected is null
If Request.Form ("Options") < >empty Then
% >

<%
' The following if statement is the value of the two collection (ServerVariables and cookies) that are compared to the request
' To prevent users from continuing to influence the results of the survey by submitting
If not Request.ServerVariables ("REMOTE_ADDR") =request.cookies ("IPAddress") Then
' Write the IP information of the client to the cookie
Response.Cookies ("IPAddress") =request.servervariables ("REMOTE_ADDR")
% >
<%
' Establish a connection (Connection) object to open the database that records the results of the survey
Set Conn=server.createobject ("ADODB. CONNECTION ")
Conn.Open "Researchdb"
% >

<%
' Define variables
Dim rs
Dim sql
Dim selected
Selected=request.form ("Options")
' Set up a collection of records (recordset



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.