Vi. Code-writing
After doing the process design, the writing code is more organized. Let's start with the simple. In writing code
Before, we have to enter some records in the database in order to do the test. First, add a survey question, and a few
Investigate the answers and enter some statistics manually.
We're going to write the surveycode.asp that shows the survey form. This file is called on other pages, so we're writing JS and VBS in a mixed way. When called, you can put it in a table with the following statement:
<SCRIPT Language="JavaScript" SRC="surveycode.asp?id=1"></SCRIPT>
According to the above process, before displaying the form, we must first determine whether the investigation exists, whether it is in progress. In addition, to submit a hidden parameter in the form to indicate the problem number (ID) of the survey, the answer is submitted with the number of the answer Vote_no
FileName surveycode.asp
!--#include file= "inc.asp"-->
<%
Id=request.querystring ("id")
If ID <> "then" if there are parameters
Opendb my ' join database
Sql= "SELECT * from survey where survey_id=" & ID "query statement
searchtable my,sql,rs ' query database
If not rs.eof then ' if there is a record of this investigation
Question=rs ("survey_question") ' Read the question
Surveytype=rs ("Survey_type") ' read out the answer type
Stime=rs ("Survey_stime") ' read out start time
Etime=rs ("Survey_etime") ' read out end time
CloseTable rs ' Close table
If Stime<now () and Etime>now () then ' if the investigation is in progress
"Output survey form below
' First output forms and issues, form submission to survey_vote.asp
%>
document.write ("<form action= ' survey_vote.asp ' target= '" _blank ' ' method= ' "' Post '");
document.write ("<table border= ' 1", "cellpadding=", "cellspacing=0" ' bordercolorligh= ', ' #000000 ');
document.write ("bordercolordark= ' #ffffff ' width= '" 100% ' align= ' center ' >< ");
document.write ("<tr> <td colspan= ' 2" ' align= ' center ' "<b>"%=server.htmlencode (question)%> </b> </td> </tr>);
<%
Sql= "Select Vote_no,vote_answer from Survey_vote where vote_id=" &id "Query answers SQL
Searchtable my,sql,rs ' Execute query
If not rs.eof then ' if there is an answer, output
For I=1 to Rs.recordcount
%>
document.write ("<tr> <td align= ' right ' ><input name= ' res ' ' type= '");
<%
If Surveytype then ' judgment type, show single selection or multiple selection
%>
document.write ("checkbox");
<%else%>
document.write ("Radio");
<%end if ' The text of the output answer and the value submitted (VOTE_NO)%>
document.write ("' Value=<%=rs" ("Vote_no")%>> </td> <td>%=rs ("Vote_answer")%> </td> </tr>);
<%
Rs.movenext
Next
The following sentence outputs a hidden parameter, passing the problem number (ID)
"and use a JS function to define the link after clicking the view
% >
document.write ("<tr> <td colspan= ' 2" "align= ' center ' ><input ' type= '" ' "' Hidden ' ' id ' ' name= '" <%=id%> ' ");
document.write ("<input type=" "Submit" ' Class=button value= ' vote ');
document.write ("The input Type=button Class=button value= ' view ' onclick= '" Jump (<%=id%>) ' ");
document.write ("</td> </tr> </tbody> </table> </form>");
function jump (ID) {
window.open ("survey_vote.asp?id=" +id, "survey")
}
<%
End If
End If
End If
CloseTable RS
Closedb my
End If
%>
Upon completion of the surveycode.asp, the following points have been identified in our implementation:
1, in Survey_vote.asp, if the QueryString parameter ID has a value, then view the result;
2, in the survey_vote.asp, if the form parameter ID has a value, you must first statistics;
3, in survey_vote.asp, the submitted form parameter res is the number of the answer vote_no;