hi ...
i wanna store in the backend sql server 2000, while validation its not at all stored... i have attached the codings ... pls check....
and another asp file as:
i wanna store in the backend sql server 2000, while validation its not at all stored... i have attached the codings ... pls check....
Code:
trial.asp
<%@ Language=VBScript %>
<%
dim rs
Set Con = Server.CreateObject("ADODB.connection")
con.CursorLocation= 3
con.ConnectionString = "driver={sql server};server=yummy;uid=gal;pwd=gal;database=pubs"
con.Open
Set rs = Server.CreateObject ("ADODB.Recordset")
session("emp_no")=Request.Form ("emp_no")
session("emp_name")=Request.Form ("emp_name")
session("sal")=Request.Form ("sal")
sub insert()
rs.Fields ("empno")=session("emp_no")
rs.Fields ("empname")=session("emp_name")
rs.Fields ("sal")=session("sal")
end sub
flag=Request.QueryString("flag")
if flag="insert" then
rs.Open "SELECT * FROM empdtl", con,2,3
rs.AddNew
insert()
rs.Update
end if
session("msg")="Records updated successfully."
Response.Redirect "trialmain.asp"
%>
and another asp file as:
Code:
trialmain.asp
<%@ Language=VBScript %>
<script language="javascript">
function formvalidation()
{
var empno=document.getElementById('emp_no');
var empname=document.getElementById('emp_name');
var sal=document.getElementById('sal');
if (isNumeric(empno,"Please enter the number")
{
if(isAlphabet(empname,"Please enter the name ")
{
isNumeric(sal,"Please enter the salary ")
{
document.f1.action ="trial.asp?flag=insert"
document.f1.submit();
return true;
}
}
}
return false;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<FORM method=post id=f1 name=f1 >
<%
Set Con = Server.CreateObject("ADODB.connection")
con.CursorLocation= 3
con.ConnectionString = "driver={sql server};server=yummy;uid=gal;pwd=gal;database=pubs"
con.Open
msg=session("msg")
session("msg") = ""
emp_no=session("emp_no")
emp_name=session("emp_name")
sal=session("sal")
%>
<FORM method=post name=fo1 id=fo1 >
<TABLE style="WIDTH: 334px; HEIGHT: 90px" cellSpacing=1 cellPadding=1 width=334
border=0 >
<TR>
<TD>Employee No</TD>
<TD><INPUT type="text" id="emp_no" value=<%=emp_no%> ></TD></TR>
<TR>
<TD>Employee Name</TD>
<TD><INPUT type="text" id="emp_name" value=<%=emp_name%> ></TD></TR>
<TR>
<TD>Salary</TD>
<TD><INPUT type="text" id="sal" value=<%=sal%> ></TD></TR></TABLE>
<P><input name="Submit1" type="submit" value="submit" onclick ="javascript:formvalidation()"></P></FORM>
</form>
</BODY>
<%
if len(msg & "") > 0 then
Response.Write "<script language=javascript>"
Response.Write "{ alert('" & msg & "');}</script>"
msg=""
end if
%>
</HTML>
Comment