OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

Redirect

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> Redirect
Page: [1]
 
 
chadb

 

Posts: 524
From: Kansas
Status: offline

 
Redirect - 8/12/2009 11:46:16   
I have a form that when you submit it, it checks a field compared to a database, and if it does not match I want to redirect them back to to ASP page with the field in red indicating that it was invalid, what is the best way I can do this?

Thanks
Chad
TexasWebDevelopers

 

Posts: 761
Joined: 2/22/2002
From: Dallas, TX
Status: offline

 
RE: Redirect - 8/12/2009 16:41:46   
Actually, this is one of those times where AJAX might be better to use.

Here is an example page: http://www.texaswebdevelopers.com/examples/simple-ajax/

Assume your Access database is named dbUsers.mdb and the field xusername is in the table called tblUsers.

Here is the code for the page that does all the work (save it as ajax_username.asp):

<%
Set xusername = Request.QueryString("xusername")
Set DBConn = Nothing
Set DBConn = Server.CreateObject("ADODB.Connection")
DBconn.CommandTimeout = 0
ConnectStr = "provider=microsoft.jet.oledb.4.0; " & "data source=" & Server.MapPath("dbUsers.mdb ") '
DBConn.Open ConnectStr
SQL = "SELECT [xusername] FROM [tblUsers] WHERE xusername='" & xusername & "' "
Set chk_xusername = Server.CreateObject("ADODB.Recordset")
chk_xusername.Open SQL, DBconn, 3, 3
If chk_xusername.EOF = False then
response.write "USERNAME ALREADY TAKEN"
Else
response.write "USERNAME IS AVAILABLE"
End if
chk_xusername.close
set chk_xusername = nothing
DBconn.close
set DBconn = nothing
%>

Here is the code for the public page that has the input form (save it as test.asp):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>AJAX test</TITLE>
<script language="javascript">
function OnChangedUsername()
{
if(document.form1.newuserid.value == "")
{
document.form1.btnCheckAvailability.disabled = true;
}
else
{
document.form1.btnCheckAvailability.disabled = false;
}
}
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq() {
http.open('get', 'ajax_username.asp?xusername='+document.form1.newuserid.value);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById("xusername_chk").innerHTML = update[0];
}
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>AJAX TEST</p>
<p>This form sends a request to a database every time there is a KeyUP. It uses the HTTP RequestObject and javascript. Using AJAX the form sends the information via a query string and talks to the database without reloading the page.</p>

<form method="post" action="javascript:void(0);" name="form1">
<table>
<tr><td><input type="newuserid" name="newuserid" id="newuserid" size="20" onKeyUp="sndReq();" /></td></tr>
<tr><td><input id="btnCheckAvailability" type="button" disabled="disabled" value="Check Availability" onClick="sndReq();"></td></tr>
<tr><td><div ID="xusername_chk"></div></td></tr>
</table>
</form>

</body>
</html>

< Message edited by TexasWebDevelopers -- 8/12/2009 16:59:01 >


_____________________________

:)

Follow us on TWITTER

(in reply to chadb)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> Redirect
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts