 |
|
ทำ login โดยใช้ javascript แร้วพอกด login user pass ถูกก้อเด้งแจ้งเตือน |
|
 |
|
|
 |
 |
|
Code (ASP)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.label{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#0066FF;
}
.tableBorder{
border:solid 1px #0066FF;
margin-top:100px;
}
.message{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
color:#0066FF;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login to Website</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form name="form1" method="get" action="" >
<table cellpadding="2px" cellspacing="1px" bgcolor="#F4F5F7" width="400px" class="tableBorder" align="center">
<tr>
<td colspan="2" bgcolor="#0066FF"> </td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
<tr>
<td align="center" colspan="2"><img src="images/key.gif" border="0" align="absbottom"/> <span class="message">Login to the Admin Panel</span></td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
<tr>
<td class="label" align="right" width="40%">Username:</td>
<td align="left" width="60%"><input name="username" type="text" maxlength="12" placeholder="Username"/></td>
</tr>
<tr>
<td class="label" align="right">Password:</td>
<td align="left"><input name="password" type="password" maxlength="12" placeholder="Password" /></td>
</tr>
<%
Dim Conn1,Conn2,Conn3,strSQL,objRec,objRec2,objRec3,IP,keyWord,ct,ct2,ct3,a,b
set Conn1 = Server.Createobject("ADODB.Connection")
Conn1.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Network.mdb"),"" , ""
strSQL = "SELECT * FROM Member WHERE (User = '"& trim(Request.QueryString("username")) &"' "
strSQL = strSQL & "and Password = '"& trim(Request.QueryString("password")) &"') "
Set x = Conn1.Execute(strSQL)
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn1, 1,3
ct=objRec.RecordCount
If Cint(ct) >=1 Then
ct=1
session("username")=trim(Request.QueryString("username"))
session("status")= x.Fields("Status").Value
Response.Redirect("home.asp")
elseif Cint(ct) =0 and (username <> "" and Password <>"") then
Response.write("<script>alert('dasa')</script>")
End if
%>
</form>
<tr>
<td class="label" align="right"> </td>
<td align="left"><input type="submit" value="Login" />
<input type="button" value="Register" OnClick="window.location='register.asp';"/></td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
</table>
</body>
</html>
Tag : ASP, JavaScript
|
ประวัติการแก้ไข 2013-06-18 14:11:19
|
 |
 |
 |
 |
Date :
2013-06-18 10:20:33 |
By :
solskjaer16 |
View :
4127 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้พวก IF กับ Session เข้ามาช่วยครับ
Code (ASP)
<% IF session("username") = "" Then %>
Alert
<% End IF%>
|
 |
 |
 |
 |
Date :
2013-06-18 11:33:55 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (ASP)
</head>
<script language="javascript">
function chkdata()
{
with(form1)
{
if(txtUser.value=='' )
{
alert('please entered text');
txtUser.focus();
return false;
}
if (txtPass.value =='')
{
alert('please entered text');
txtUser.focus();
return false;
}
<% IF session("username") ="" Then %>
return alert('please login');
<%End IF%>
}
}
</script>
<body>
<form name="form1" method="get" action="" >
<table cellpadding="2px" cellspacing="1px" bgcolor="#F4F5F7" width="400px" class="tableBorder" align="center">
<tr>
<td colspan="2" bgcolor="#0066FF"> </td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
<tr>
<td align="center" colspan="2"><img src="images/key.gif" border="0" align="absbottom"/> <span class="message">Login to the Admin Panel</span></td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
<tr>
<td class="label" align="right" width="40%">Username:</td>
<td align="left" width="60%"><input name="txtUser" type="text" maxlength="12" placeholder="Username"/></td>
</tr>
<tr>
<td class="label" align="right">Password:</td>
<td align="left"><input name="txtPass" type="password" maxlength="12" placeholder="Password" /></td>
</tr>
<%
Dim Conn1,Conn2,Conn3,strSQL,objRec,objRec2,objRec3,IP,keyWord,ct,ct2,ct3,a,b
set Conn1 = Server.Createobject("ADODB.Connection")
Conn1.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Network.mdb"),"" , ""
strSQL = "SELECT * FROM Member WHERE (User = '"& trim(Request.QueryString("username")) &"' "
strSQL = strSQL & "and Password = '"& trim(Request.QueryString("password")) &"') "
Set x = Conn1.Execute(strSQL)
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn1, 1,3
ct=objRec.RecordCount
If Cint(ct) >=1 Then
ct=1
session("username")=trim(Request.QueryString("username"))
session("status")= x.Fields("Status").Value
End if
%>
</form>
<tr>
<td class="label" align="right"> </td>
<td align="left"><input type="submit" value="Login" onClick="return chkdata();"/>
<input type="button" value="Register" OnClick="window.location='register.asp';"/></td>
</tr>
<tr>
<td colspan="2" class="label"> </td>
</tr>
</table>
</body>
</html>
|
ประวัติการแก้ไข 2013-06-18 14:11:39 2013-06-18 14:14:25
 |
 |
 |
 |
Date :
2013-06-18 11:50:25 |
By :
solskjaer16 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอา code นี้ไปลองใช้ดูครับ
JavaScript
<body>
<script language="javascript">
function chk1Submit()
{
if(isNaN(document.form1.textf1.value))
{
alert('ใส่เฉพาะตัวเลขเท่านั้น');
document.form1.textf1.focus();
return false;
}
else if(document.form1.textf1.value == "")
{
alert('ไม่ได้ใส่ตัวเลข 10 หลัก');
document.form1.textf1.focus();
return false;
}
else if(document.form1.textf1.value.length < 10)
{
alert('ใส่ตัวเลขไม่ครบ 10 หลัก');
document.form1.textf1.focus();
return false;
}
document.form1.submit();
}
</script>
<form id="form1" name="form1" method="post" action="(ชื่อของไฟล์ที่จะส่งไป).asp">
<div align="left"> User ID :
<input type="text" name="textf1" maxlength="10" />
<input name="Sch" type="submit" id="Sch" value="ค้นหาข้อมูล" OnClick="JavaScript:return chk1Submit();"/>
</div>
</form>
</body>
|
ประวัติการแก้ไข 2013-06-18 14:12:20
 |
 |
 |
 |
Date :
2013-06-18 14:11:25 |
By :
KT-Raiden |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|