Monday, 26 January 2009

ajax1.asp code



<!--#include file="../../SQLconn.asp" -->


<%
Dim UserID__MMColParam


If (Request.QueryString("UI") <> "") Then 'start of check UI is numeric, connect to database and then retrieve the Recordset
function IsNotNumeric(pStr, pDefaultValue)
dim sTemp
sTemp = pStr
if isNuLL(sTemp) OR sTemp = "" OR not isNumeric(sTemp) then
sTemp = pDefaultValue
end if
IsNotNumeric = sTemp
end function
%>

<%
UserID__MMColParam = IsNotNumeric(Request.QueryString("UI"),0)

SQL = "SELECT TOP 1 * FROM USERID WHERE UI = "& UserID__MMColParam

Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = conn
Recordset1.Source = SQL
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0

if not Recordset1.BOF and not Recordset1.EOF then
Username = (Recordset1.Fields.Item("Username").Value)
DealtWith =(Recordset1.Fields.Item("DealtWith").Value)
if not DealtWith then
styleslider = "style='left:52px'"
end if
end if

End If 'end of check UI is numeric, connect to database and then retrieve the Recordset

%>
<style type="text/css">
.ui-slider { width: 80px; height: 23px; position: relative; background-repeat: no-repeat; background-position: center; }
.ui-slider-handle { position: absolute; z-index: 1; height: 23px; width: 12px; top: 0px; left: 0px; }
.label-1 { position: absolute; left: 0; top: -1.5em; font-size: 0.8em;}
.label-2 { position: absolute; right: 0; top: -1.5em; font-size: 0.8em;}
</style>

<script type="text/javascript">
$(function(){
//slider
$('#slider1').slider({
stepping: 10,
min: 0,
max: 10,
range: true,
stop: function (event, ui) {
checkit();
}
});

});

function edit() {
document.getElementById("txtname").style.display="block";
document.getElementById("btnup").style.display="block";
document.getElementById("spname").style.display="none";
document.getElementById("btned").style.display="none";
document.getElementById("txtname").focus();
}
var ui = <%=UserID__MMColParam%>;

function saveit() {
var sname = document.getElementById("txtname").value;
$.ajax({
type: "POST",
url: "save1.asp",
data: "name="+sname+"&UI="+ui+"",
success: function(msg){
document.getElementById("txtname").style.display="none";
document.getElementById("btnup").style.display="none";
document.getElementById("spname").style.display="block";
document.getElementById("btned").style.display="block";
document.getElementById("txtname").value = sname;
document.getElementById("spname").innerHTML = sname;
document.getElementById("welcome").innerHTML = sname;
}
});
}

function checkit(){
var sdata = 0;
if (document.getElementById('divslide').style.left == "0pt" || document.getElementById('divslide').style.left == "0px") {
sdata = 1;
} else {
sdata = 0;
}

$.ajax({
type: "POST",
url: "save2.asp",
data: "val="+sdata+"&UI="+ui+"",
success: function(msg){}
});
}
</script>
<form name="form1" action="">
<table cellpadding="1">
<tr height="48">
<td>User Name</td>
<td>
<span id="spname"><%=Username%></span>
<input name="txtname" id="txtname" type="text" value="<%=Username%>" style="display:none" />
</td>
</tr>
<tr>
<td>
<input id="btned" type="button" value="Edit" onclick="edit()" style="width:65px" />
<input id="btnup" type="button" value="Save" onclick="saveit()" style="width:65px;display:none" />
</td>
</tr>
<tr height="50"><td> </td></tr>
<tr>
<td>
<div id="slider1" class="ui-slider">
<div class="ui-slider-handle" id="divslide" <%=styleslider%>></div>
<span class="label-1">Yes</span>
<span class="label-2">No</span>
</div>
</td>
</tr>
</table>
</form>
<%
conn.close
set conn=nothing
%>

No comments:

Post a Comment