<%
Option Explicit
Session.CodePage=65001
Response.Charset="UTF-8"
Dim rs, conn, command, connection
Dim fieldNames, hiddenValues, savedValues(8), activeValues(8), idx, item, numAffected
if LCase(request.servervariables("HTTP_METHOD"))="post" then
Dim changed, whatChanged
changed=false
command = "UPDATE companys SET "
fieldNames = Split(request.form("sav_fieldNames"),",")
for idx=0 to 8
activeValues(idx)=request.form(fieldNames(idx))
savedValues(idx)=request.form("sav_"&fieldNames(idx))
if activeValues(idx)<>savedValues(idx) then
changed=true
whatChanged = whatChanged & fieldNames(idx) & " changed from; " & savedValues(idx) & " to: " & activeValues(idx) & "<br>" & vbLF
command = command & fieldNames(idx) &"='"& activeValues(idx) & "', "
end if
next
command = Left(command, Len(command)-1) & " WHERE (id=15);"
Set conn = Server.CreateObject("ADODB.Connection")
connection = Application("examples")
conn.open connection
conn.Execute command, numAffected, 128
if not err then
if numAffected > 0 then
' send mail, body is whatChanged
end if
end if
else
command = "SELECT id, company, type, address, address1, city, state, postalCode, phoneNumber FROM companys WHERE (id=15);"
Set conn = Server.CreateObject("ADODB.Connection")
connection = Application("examples")
conn.open connection
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.open command, conn, 3, 1, 1
if NOT (rs.bof AND rs.eof) then
idx=0
for each item in rs.fields
fieldNames=fieldNames & item.name & ","
hiddenValues=hiddenValues & "<input type='hidden' name='sav_"&item.name&"' value='"&item&"'>"
activeValues(idx)=item
idx=idx+1
next
' trim the trailing comma
fieldNames=Left(fieldNames,Len(fieldNames)-1)
hiddenValues = "<input type='hidden' name='sav_fieldNames' value='"&fieldNames&"'>" & hiddenValues
rs.close
Set rs = nothing
conn.close
end if
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005, 2006 Roderick Divilbiss">
<title>Track Record Changes</title>
<style>
<!--
.lbl {
position:relative;
width:115px;
float:left;
}
-->
</style>
</head>
<body>
<form name="frm" action="changes.asp" method="post">
<p><label class="lbl" for="id">ID</label><input type="text" size="20" name="id" id="id" value="<%=activeValues(0)%>" readonly><br>
<label class="lbl" for="company">Company</label><input type="text" size="20" name="company" id="company" value="<%=activeValues(1)%>"><br>
<label class="lbl" for="type">Type</label><input type="text" size="20" name="type" id="type" value="<%=activeValues(2)%>"><br>
<label class="lbl" for="address">Address</label><input type="text" size="20" name="address" id="address" value="<%=activeValues(3)%>"><br>
<label class="lbl" for="address1">Address (cont.)</label><input type="text" size="20" name="address1" id="address1" value="<%=activeValues(4)%>"><br>
<label class="lbl" for="city">City</label><input type="text" size="20" name="city" id="city" value="<%=activeValues(5)%>"><br>
<label class="lbl" for="state">State</label><input type="text" size="20" name="state" id="state" value="<%=activeValues(6)%>"><br>
<label class="lbl" for="postalCode">Zip Code</label><input type="text" size="20" name="postalCode" id="postalCode" value="<%=activeValues(7)%>"><br>
<label class="lbl" for="phoneNumber">Phone Number</label><input type="text" size="20" name="phoneNumber" id="phoneNumber" value="<%=activeValues(8)%>"><br>
<%=hiddenValues%>
<input type="submit" value="Submit"><br>
<!-- FOR EXAMPLE ONLY -->
<b>Changes: </b><%=whatChanged%><br>
<b>Command: </b><%=command%>
</form>
</div>
</body>
</html>
Client Side Includes Using JavaScript
Creating A JavaScript Slider Input in JavaScript
Creating Conditional Links With ASP
Dynamically Adding Rows and Fields To A Table Based Form
Geo-Coding IP Addresses
How To Make A Pop Over Menu
JavaScript Date Validation DD/MM/YYYY
JavaScript Date Validation MM/DD/YYYY
Parameterized SQL Using Multiple Form Inputs and Filtering
Play A WAV File On Mouseover
Pop Over Form
Resorting A Multi-Dimensional Table Using Client-Side JavaScript
Scripting Remote Images in JavaScript
Using AJAX to Return HTML For Dynamic Forms
Using Images For CAPTCHA
Using Parameterized SQL with ASP and MS Access
Why JavaScript As The HREF Of A Link Is Bad