How to use ASP to establish voting mechanism on your own website (ii.)

Source: Internet
Author: User
Tags access
Batman Translation Finishing

4. Document Default.asp
<%
id = Request ("id")
If ID = "" Then
ID = 30
End If
Title = "Polls (Create your own poll)"
%>


<title>asp polls</title>

<script language= "JavaScript" >

function Gatherform (form) {
if (form. mode[0].checked) {
Form.submit ();
}else{
Form.action= "collect.asp";
Form.submit ();
}
}

</script>


<body>
<div align= "left" ><br" >another Joint product from <a href= "Http://www.ncws.com/tippycow" >tipped Cow development</a> and <a href= "http://dstoflet.calweb.com" >adrenalin labs</a>
<br><br>
</div>
<table width= "100%" cellspacing= "0" cellpadding= "2" >
<tr>
&LT;TD align= "left" width= "25%" valign= "Top" class= "bold" >
<form action= "Default.asp" >
<table width= "border=" 1 "bordercolor= #ccccff >
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor= #4f4f4f ><tr>
&LT;TD colspan=3 bgcolor= #000000 align=center class= "bold2" >select A poll</td>
</tr><tr>
&LT;TD colspan=3 bgcolor= #000000 align=center>
<select name= "ID" class= "Input" >
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open application ("Asppolldsn")
sql = "SELECT * FROM Poll"
Set RS = conn. Execute (SQL)
Do but not Rs. Eof
%>


<option value= "<%=rs (" ID ")%>" ><%=rs ("Pollname")%>

<%
Rs. MoveNext
Loop
%>

</select>
</tr>

<tr>
&LT;TD colspan=3 align=right bgcolor= #FFFFFF class= "Bold" >
Vote in Poll:<input type= "Radio" name= "Mode" value= "Vote" checked><br>
View Results:<input type= "Radio" name= "Mode" value= "View" >
</td></tr>

<tr>
&LT;TD colspan=3 align=right bgcolor= #000000 align=center>
<input type= "button" value= "Go" class= "inline" >
</td></tr>

</table>
</td>
</tr>
</table></form><br>
<div align= "left" class= "bold" >
<a href= "create_poll1.asp" >create your own poll</a><br>
<a href= ' javascript:history.back () ' >Back</a>
</div>
</td>

&LT;TD align= "center" width= "75%" valign= "Top" >
<table width= "border=1 cellspacing=2 cellpadding=0 bordercolor= #ccccff ><tr><td>
<form method= "POST" action= "collect.asp" >
<input type= "hidden" name= "id" value= "<%=id%>" >

<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open application ("Asppolldsn")
sql = "SELECT * from Poll where id =" & ID
Set RS = conn. Execute (SQL)
If Rs. EOF = False Then
%>

<table border=0 cellspacing=0 cellpadding=10 bgcolor= #4f4f4f ><tr>
<!--<td colspan=3 bgcolor= #2f2f4f align=center><font face= "Verdana" color= #f5fcdc >
Poll: <%=rs ("Pollname")%>
</td>-->
</tr><tr>
&LT;TD colspan=3 bgcolor= #000000 align=left class= "Bold2" ><%=rs ("Pollquestion")%>
</tr>
<%
For I=1 to 5
Choice = rs ("Choice" & I)
If choice <> "" Then
%>
<tr> <!--<td width=50 colspan=1 bgcolor= #4f4f4f > </td>-->
&LT;TD colspan=2 bgcolor= #FFFFFF class= "bold" align= "left" >
&LT;%=CHOICE%&GT;&LT;/TD&GT;&LT;TD bgcolor= #FFFFFF align= "left" ><input type= "Radio" name= "Choice" value= "< %=i%> ">
</td></tr>
<%
End If
Next
%>

</tr>
<% If rs ("GetName") = "1" Then%>
&LT;TR&GT;&LT;TD colspan=1 align=right bgcolor= #FFFFFF class= "Bold" >
Your name:</td>
&LT;TD colspan=2 align=right bgcolor= #FFFFFF >
<input type= "text" name= "name" >
</td></tr>
<% End If%>
<tr>
&LT;TD colspan=3 align=right bgcolor= #000000 align=center>
<input type= "Submit" value= "Submit Vote" class= "inline" >
</td></tr>
</table>

<%
Else
Response.Write "Invalid Poll Id request!"
End If
%>
</td></tr></form></table>

</td>
</tr>
</table>
</body>

5. Document Global.asa
<script language= "VBScript" runat= "SERVER" >

Sub Application_OnStart
Application ("asp_poll") = "Asp_poll"
cnstring = "Driver={microsoft Access DRIVER (*.mdb)};"
cnstring = cnstring & "dbq=" & Server.MapPath ("Events.mdb")
Application ("asppolldsn") = cnstring
End Sub
</SCRIPT>

6. Document Pool.inc
<%
DBPath = Server.MapPath ("/poll/events.mdb")
ID = 28
If request.cookies ("pollid") = CStr (ID) Then
Showdisplay
Else
Showvote
End If

Function converttopercent (Total, SZ)
If Sz = 0 Then
Converttopercent = "0%"
Else
Converttopercent = FormatPercent (sz/total, 2)
End If
End Function

Sub Showvote

%>

<div align=right>
<table width=125 border=1 cellspacing=0 cellpadding=0><tr><td>
<form method= "POST" action= "/poll/collect.asp" >
<input type= "hidden" name= "id" value= "<%=id%>" >
<input type= "hidden" name= return_page "value=" <%=request.servervariables ("Path_info")%> ">
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & DBPath
Conn.Open Dsnpath
sql = "SELECT * from Poll where id =" & ID
Set RS = conn. Execute (SQL)
If Rs. EOF = False Then
%>

<table width=125 border=0 cellspacing=0 cellpadding=2 bgcolor= #4f4f4f >
<tr>
&LT;TD colspan=3 bgcolor= #2f2f4f align=center>
<%=rs ("Pollquestion")%>
</td>
</tr>
<%
For I=1 to 5
Choice = rs ("Choice" & I)
If choice <> "" Then
%>
<tr>
&LT;TD colspan=2 bgcolor= #000000 valign=top width=80%>
<%=choice%> </td><td valign=top colspan=1 width=20% bgcolor= #000000 > <input type= "Radio" name= " Choice "value=" <%=I%> ">
</td></tr>
<%
End If
Next
%>

<tr>
&LT;TD colspan=3 align=center bgcolor= #2f2f4f align=right>
<input type= "Submit" value= "Submit" class=nav>
</td></tr>
</table>
<%
End If
%>

</td></tr></form></table>

</center>

<%

End Sub


Sub Showdisplay

Set conn = Server.CreateObject ("ADODB. Connection ")
sql = "SELECT * from Poll where id =" & Cint (ID)
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & DBPath
Conn.Open Dsnpath
Set rs = conn.execute (SQL)
If Rs. EOF = False Then
Dim Choices (6)
Dim Responses (6)
For I=1 to 5
Choice = rs ("Choice" & I)
Choices (I) = Choice
If choice <> "" Then
Set conn2 = Server.CreateObject ("ADODB. Connection ")
sql = "Select COUNT (pollanswer) from pollresults where Pollid =" & Cint (ID) & "and pollanswer=" & I
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & DBPath
Conn2.open Dsnpath
Set rs2 = conn.execute (SQL)
If rs2. EOF = False Then
Responses (I) = rs2 (0)
End If
Rs2. Close
Conn2. Close
End If
Next
%>
<div align= "Right" >
<table border=1 cellspacing=0 cellpadding=2><tr><td>
<table width=125 border=0 cellspacing=0><tr>
&LT;TD colspan=2 bgcolor= #2f2f4f align=center class=orgbold>asp Poll
</td></tr>
&LT;TR&GT;&LT;TD colspan=2 align=center bgcolor= #ccccff class=black>
Q:<%=rs ("Pollquestion")%>
</td></tr>

<%
Total = 0
For I=1 to 5
Responsecount = Responses (I)
If responsecount <> "" Then
Total = Total + Cint (responsecount)
End If
Next
For I=1 to 5
Choice = Choices (I)
Responsecount = Responses (I)
If choice <> "" Then
Response.Write "<tr><td colspan=1 align=left><font face= ' Verdana ' size=-1 color= #f0f0f0 >"
Response.Write Choice
Response.Write "</td>"
Response.Write "<td>" & Converttopercent (Total, Responsecount) & "</td>"
Response.Write "</tr>"
End If
Next
Response.Write "</table></td></tr></table></div>"
End If
End Sub
%>
</div>


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.