<%@ Language=VBScript %> <% Option Explicit %> <!--#include virtual="/adovbs.inc"--> <% Const iWidth = 150 Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _ Server.MapPath("Poll.mdb") & ";" objConn.Open Dim objRS Set objRS = Server.CreateObject("ADODB.Recordset") 'Determine if this person has already voted today... Dim strVoted strVoted = Request.Cookies("Voted") Dim strSQL %> <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> <!-- // This function makes sure that the user selected a voting option. function OneOptionChecked() { var i; // Let's iterate through our voting options, returning true if // we come across a checked radio box for (i = 0; i < document.frmPoll.radPoll.length; i++) if (document.frmPoll.radPoll[i].checked) return true; // If we reach this point, then the user didn't check any voting options alert("You must select what you want to vote for\nbefore you can submit your vote!"); return false; } // --> </SCRIPT> <BODY> <% if strVoted = "Yes" then strSQL = "SELECT PollOption.PollOptionID, PollOption.QuestionText, PollOption.Votes, " & _ "Poll.PollQuestion " & _ "FROM Poll INNER JOIN PollOption ON Poll.PollID = PollOption.PollID " & _ "WHERE Poll.DateStart <= #" & Date & "# AND Poll.DateEnd >= #" & Date & "#;" objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly 'We need to create a dynamic array just big enough to hold all of our voting options Dim PollOptions() Redim PollOptions(objRS.RecordCount,2) Dim iCount, iTotalVotes, strPollName iCount = 0 iTotalVotes = 0 strPollName = CStr(objRS("PollQuestion")) Do While Not objRS.EOF PollOptions(iCount,1) = CInt(objRS("Votes")) PollOptions(iCount,2) = CStr(objRS("QuestionText")) iTotalVotes = iTotalVotes + PollOptions(iCount,1) iCount = iCount + 1 objRS.MoveNext Loop %> <TABLE BORDER=0 CELLSPACING=0 WIDTH=<%=iWidth%>> <TR><TH BGCOLOR=NAVY><FONT COLOR=WHITE FACE=Arial SIZE=2> <%=strPollName%> </FONT></TH></TR> <TR> <TD BGCOLOR=GRAY> <% Dim iLoop For iLoop = 0 to iCount-1 %> <FONT FACE=Arial SIZE=2><%=PollOptions(iLoop,2)%> (<%=FormatPercent(PollOptions(iLoop,1)/iTotalVotes,1)%>)</FONT> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR><TD WIDTH=<%=CInt((PollOptions(iLoop,1)/iTotalVotes)*iWidth)%> BGCOLOR=YELLOW> &nbsp;</TD> </TR> </TABLE> <BR> <% Next %> <FONT FACE=Arial SIZE=2>Total Votes: <%=iTotalVotes%></FONT> </TD></TR></TABLE> <% else strSQL = "SELECT PollOption.PollOptionID, PollOption.QuestionText, Poll.PollQuestion " & _ "FROM Poll INNER JOIN PollOption ON Poll.PollID = PollOption.PollID " & _ "WHERE Poll.DateStart <= #" & Date & "# AND Poll.DateEnd >= #" & Date & "#;" objRS.Open strSQL, objConn %> <FORM METHOD=POST ACTION="pollResults.asp" ONSUBMIT="return OneOptionChecked();" NAME=frmPoll> <TABLE BORDER=0 CELLSPACING=0 WIDTH=<%=iWidth%>> <TR><TH BGCOLOR=NAVY><FONT COLOR=WHITE FACE=Arial SIZE=2> <%=objRS("PollQuestion")%> </FONT></TH></TR> <TR> <TD BGCOLOR=GRAY> <% Do While Not objRS.EOF %> <INPUT TYPE=RADIO NAME=radPoll VALUE="<%=objRS("PollOptionID")%>"> <FONT FACE=Arial SIZE=2><%=objRS("QuestionText")%></FONT> <BR> <% objRS.MoveNext Loop %> <INPUT TYPE=HIDDEN NAME="URLFrom" VALUE="<%=Request.ServerVariables("SCRIPT_NAME")%>"> <BR><CENTER><INPUT TYPE=SUBMIT VALUE="Vote!"></CENTER> </TD></TR></TABLE> </FORM> <P> <% end if %> </BODY> </HTML> <% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>