关闭

自己写的一个用AJAX实现的留言系统

标签: ajaxemailcommentsinputborderxmlhttprequest
1113人阅读 评论(1) 收藏 举报
分类:

 

//write.asp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../images/css.css" rel="stylesheet" type="text/css">
<title>Dry English Online</title>
<style type="text/css">
<!--
.style1 {
 font-family: Arial;
 font-size: 9.0pt;
 color: black;
}
.style2 {font-size: 10.0pt}
#msg {
 position:absolute;
 left:284px;
 top:20px;
 width:350px;
 height:25px;
 z-index:1;
}
-->
</style></head>
<body>
<!-- onload="javascript:openWin()" -->
<div id="msg"></div>

<!--<table width="200" height="20" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td id="msg">&nbsp;</td>
  </tr>
</table>
-->
<table width="778" border="0" align=center cellpadding="0" cellspacing="0" bgcolor="#DEDFE2" class="top4">  

  <tr>  

    <td>  

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="table1">                  
  <tr>                   
    <td valign="top">                   
      <div align="center">              
        <center>              
          <table border="0" cellspacing="1" width="663" height="30" id="table2"> 
            <tr> 
              <td> 
                <p align="center" style="margin-top: 6"><font face="Tahoma" size="5" color="#A71812"><b>Contract 

                Us</b></font>
                </td> 
            </tr> 
          </table> 
        </center>  
      </div> 
    </td> 
  </tr> 
</table>  
    </td> 
  </tr> 
  <tr>  
    <td height="280">  
        <div align="left">
          <table width="600" border=1 align="center" cellpadding="5" cellspacing="0" bordercolorlight="#800000" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
            <tr>
              <td ALIGN="left" width="76"  height=25><b>Name</b></td>
              <td width="371" height=25 ><input TYPE="TEXT" NAME="Contact_FullName" SIZE="20" id="Contact_FullName"></td>
            </tr>
            <tr>
              <td ALIGN="left" width="76" ><b>Signature</b></td>
              <td width="371"><input TYPE="TEXT" NAME="Contact_Title" SIZE="20" id="Contact_Title"></td>
            </tr>
            <tr>
              <td ALIGN="left" width="76" height="25"><b>Company</b></td>
              <td width="371" ><input TYPE="TEXT" NAME="Contact_Organization" SIZE="20" id="Contact_Organization"></td>
            </tr>
            <tr>
              <td ALIGN="left" width="76" height="24"><b>Tel</b></td>
              <td width="371" ><input TYPE="TEXT" NAME="Contact_TEL" SIZE="20" MAXLENGTH="25" id="Contact_TEL"></td>
            </tr>
            <tr>
              <td ALIGN="left" width="76" height="25"><b>Fax</b></td>
              <td width="371" ><input TYPE="TEXT" NAME="Contact_FAX" SIZE="20" id="Contact_FAX"> </td>
            </tr>
            <tr>
              <td ALIGN="left" width="76" ><b>E-mail</b></td>

              <td width="371" ><input TYPE="TEXT" NAME="Contact_Email" SIZE="20" MAXLENGTH="50" id="Contact_Email"></td>
            </tr>

            <tr>
              <td ALIGN="left" width="76" ><b>Address</b></td>

              <td width="371" >
    <input TYPE="TEXT" NAME="Contact_Address" SIZE="20" id="Contact_Address"></td>
            </tr>

            <tr>
              <td ALIGN="left" width="76" ><b>Comments</b></td>

              <td width="371" ><textarea rows="8" name="comments" cols="40" id="comments"></textarea></td>
            </tr>
          </table>

        </div>
<div align="center">
  <input name="mess_sbt" TYPE="button" id="mess_sbt" style="color: #A71812; margin-top: 16" VALUE="Submit" onClick="Check()">  
   
</div>

    </td> 

  </tr> 
</table>                 
<script src="ajax.js"></script>
</body>                 
</html>             

//ajax.js

function GE(a){return document.getElementById(a);}
function Check(){
 if(GE('Contact_FullName').value==''||GE('Contact_Title').value==''){
 alert('Name or Signature is required!');
 GE('Contact_FullName').focus();
 return false;
 }
 if(GE('Contact_Address').value==''){
 alert('Address is required!');
 GE('Contact_Address').focus();
 return false;
 }
 if(GE('Contact_FAX').value==''){
 alert('FAX is required!');
 GE('Contact_FAX').focus();
 return false;
 }
 if(GE('Contact_Organization').value==''){
 alert('Company is required!');
 GE('Contact_Organization').focus();
 return false;
 }
 if (GE('Contact_TEL').value==''){
 alert('Tel is required!');
 GE('Contact_TEL').focus();
 return false;
 }
 if(GE('Contact_Email').value.length!=0)
   {
  if (GE('Contact_Email').value.charAt(0)=="." ||       
    GE('Contact_Email').value.charAt(0)=="@"||      
    GE('Contact_Email').value.indexOf('@', 0) == -1 ||
    GE('Contact_Email').value.indexOf('.', 0) == -1 ||
    GE('Contact_Email').value.lastIndexOf("@")==GE('Contact_Email').value.length-1 ||
    GE('Contact_Email').value.lastIndexOf(".")==GE('Contact_Email').value.length-1)
   {
    alert('Email format is incorrect!');
    GE('Contact_Email').focus();
    return false;
    }
    }
 var X=new ActiveXObject("Msxml2.XMLHTTP");
 if(X){
  GE('mess_sbt').disabled=true;
  X.onreadystatechange=function(){
//   alert(X.readyState);
   if(X.readyState==4){
    if(X.status==200){
//     alert(X.status);
     eval(X.responseText);
    }
    else{GE('msg').innerHTML=X.statusText}
   }
   else{
    GE('msg').innerHTML="<div style='width=100%; background-color=brown; height=50px; padding-top=10px;'><font color=white>Sending...</font></div>";
   }
  };
  X.open('POST','send.asp',true);
  X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  var SendData = 'Contact_FullName='+GE('Contact_FullName').value+'&Contact_Title='+GE('Contact_Title').value+
  '&Contact_Organization='+GE('Contact_Organization').value+'&Contact_TEL='+GE('Contact_TEL').value+'&Contact_FAX='
  +GE('Contact_FAX').value+'&Contact_Email='+GE('Contact_Email').value+'&Contact_Address='
  +GE('Contact_Address').value+'&comments='+GE('comments').value
  X.send(SendData)
 }
 else{
 GE('msg').innerHTML='你的浏览器不支持XMLHttpRequest'
 }
}

//send.asp

<%@ LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include virtual="/_inc/conn.asp"-->
<%
name=request.Form("Contact_FullName")
Signature=request.Form("Contact_Title")
Address=request.Form("Contact_Address")
company=request.form("Contact_Organization")
Fax=request.form("Contact_FAX")
Tel=request.form("Contact_tel")
email=trim(request.form("Contact_Email"))
company=replace(trim(request.form("Contact_Organization")),"'","")
comments=replace(trim(request.form("comments")),"'","")
'*********写入数据库********
set rs = server.CreateObject("adodb.recordset")
rs.open "select * from en_mess",conn,1,3
rs.addnew
rs("Contact_Title")=Signature
rs("Contact_FullName")=name
rs("Contact_Address")=Address
rs("Contact_Organization")=company
rs("Contact_FAX")=Fax
rs("Contact_tel")=Tel
rs("Contact_Email")=email
rs("comments")=comments
rs("time")=date()
rs.update
rs.close
set rs = nothing
'*********写入完毕***********
response.Write "location.href='success.asp';"
%>

演示网址:http://english.dry.com.cn/message/write.asp

这个是我自己写的一个网站的留言系统,做的比较粗糙,只是写入数据库而已,如果结合XML,就和CSDN的留言板差不多了。

    

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27260次
    • 积分:418
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:24篇
    • 译文:0篇
    • 评论:10条
    最新评论