javacript验证gridview模板列
Code
function ValidateGridViewScore()
{
var date=new Date();
var y=date.getYear();
if(y<10) y="0"+y;
var m=date.getMonth()+1;
if(m<10) m="0"+m;
var d=date.getDate();
if(d<10) d="0"+d;
var timeNow=y+"-"+m+"-"+d;
var txtKSTime=document .getElementById ("txtKssj");
var ddlstGradeLx= document .getElementById ("ddlstGradeLx");
var gv=document .getElementById ("gvGradeInput");
var txtCj_Ps_Bl=document .getElementById ("txtPscjBl");
var txtCj_Test_Bl=document .getElementById ("txtSycjBl");
var txtCj_Jm_Bl=document .getElementById ("txtJmcjBl");
if(txtKSTime.value.length==0)
{
alert("请选择考试时间!");
return false;
}
else
{
if(txtKSTime.value>timeNow)
{
alert("所选择的考试时间不能大于当前时间!");
return false;
}
}
if(ddlstGradeLx.selectedIndex==0)
{
alert("请选择保存总评成绩格式!");
return false;
}
if(txtCj_Ps_Bl.value.length==0&&txtCj_Test_Bl.value.length==0&&txtCj_Jm_Bl.value.length==0)
{
alert("比例设置不能为空!");
return false;
}
var btnSave=document .getElementById ("btnSubmit");
var flag=0;
var flagCj=0;
var flagZCj=0;
var txtKSTime=document .getElementById ("txtKssj");
var ddlstGradeLx=document .getElementById ("ddlstGradeLx");
var pscjBl=document .getElementById ("txtPscjBl");
var sycjBl=document .getElementById ("txtSycjBl");
var jmcjBl=document .getElementById ("txtJmcjBl");
var array=new Array();
for(m=0;m<gv.rows.length;m++)
{
for(n=0;n<4;n++)
{
array[m,n]=0;
}
}
if(pscjBl.value.length>0&& sycjBl.value.length>0&&jmcjBl.value.length>0)
{
pBl=parseInt(pscjBl.value);
sBl=parseInt(sycjBl.value);
jBl=parseInt(jmcjBl.value);
if((pBl+sBl+jBl)!=100)
{
alert ("比例之和必须为100%");
return false ;
}
else
{
for( i=1;i<gv.rows.length;i++)
{
var score_ZCj=document.getElementById(gv.rows[i].cells[5].firstChild.id).value;
if(score_ZCj==""||score_ZCj==null)
{
flagZCj=1;
}
}
if(flagZCj==0)
{
for( i=1;i<gv.rows.length;i++)
{
for(m=0;m<gv.rows.length;m++)
{
for(n=0;n<4;n++)
{
array[m,n]=0;
}
}
var txtCj_Ps=document.getElementById(gv.rows[i].cells[2].firstChild.id)
var txtCj_Test=document.getElementById(gv.rows[i].cells[3].firstChild.id)
var txtCj_Jm=document.getElementById(gv.rows[i].cells[4].firstChild.id)
var txtCj_Total=document.getElementById(gv.rows[i].cells[5].firstChild.id)
var score1=txtCj_Ps.value;
var score2=txtCj_Test.value;
var score3=txtCj_Jm.value;
var score4=txtCj_Total.value;
if(score1==""||score1==null)
{
score1=0;
}
if(score2==""||score2==null)
{
score2=0;
}
if(score3==""||score3==null)
{
score3=0;
}
if(score4==""||score4==null)
{
flagZCj=1;
}
txtCj_Ps.style.color = "black";
txtCj_Test.style.color = "black";
txtCj_Jm.style.color = "black";
txtCj_Total.style.color = "black";
if(score1<0||score1>100||score2<0||score2>100||score3<0||score3>100||score4<-3||score4>100)
{
if(score1<0||score1>100)
{
array[i,0]=1;
flag=1;
}
if(score2<0||score2>100)
{
array[i,1]=2;
flag=1;
}
if(score3<0||score3>100)
{
array[i,2]=3;
flag=1;
}
if(score4<-3||score4>100)
{
array[i,3]=4;
flag=1;
}
for(var j=0;j<4;j++)
{
if(array[i,j]==1)
{
txtCj_Ps.style.color = "red";
}
if(array[i,j]==2)
{
txtCj_Test.style.color = "red";
}
if(array[i,j]==3)
{
txtCj_Jm.style.color = "red";
}
if(array[i,j]==4)
{
txtCj_Total.style.color = "red";
}
}
}
else
{
if(score1!=0||score2!=0||score3!=0)
{
if(score1>=0&&score2>=0&&score3>=0&&score4>=0)
{
var ZCj=(parseInt(score1)*pBl +parseInt(score2)*sBl +parseInt(score3)*jBl)/100;
var Cj=parseInt(score4);
if(Math.abs(ZCj-Cj)>1)
{
txtCj_Ps.style.color = "red";
txtCj_Test.style.color = "red";
txtCj_Jm.style.color = "red";
txtCj_Total.style.color = "red";
flagCj=1;
}
else
{
txtCj_Ps.style.color = "black";
txtCj_Test.style.color = "black";
txtCj_Jm.style.color = "black";
txtCj_Total.style.color = "black";
}
}
else
{
if(score4==-1||score4==-2||score4==-3)
{
txtCj_Total.style.color = "black";
}
}
}
}
}
}
if(flagZCj==1)
{
alert("总成绩不能为空,可以为零!");
return false;
}
if(flag==1||flagCj==1)
{
if(flag==1)
{
btnSave.disabled =true ;
alert("成绩数值必须在0到100之间!总成绩可以为-1,-2,-3!不合格的成绩将会以红色字体显示!");
}
if(flagCj==1)
{
btnSave.disabled =true ;
alert ("平时成绩*比例+实验成绩*比例+卷面成绩*比例之和不等于总成绩!将会以红色字体显示不正确的成绩!");
}
}
else
{
btnSave.disabled =false;
alert ("可以录入,点击提交按钮录入成绩!");
}
}
}
}
function ValidateGridViewScore()
{
var date=new Date();
var y=date.getYear();
if(y<10) y="0"+y;
var m=date.getMonth()+1;
if(m<10) m="0"+m;
var d=date.getDate();
if(d<10) d="0"+d;
var timeNow=y+"-"+m+"-"+d;
var txtKSTime=document .getElementById ("txtKssj");
var ddlstGradeLx= document .getElementById ("ddlstGradeLx");
var gv=document .getElementById ("gvGradeInput");
var txtCj_Ps_Bl=document .getElementById ("txtPscjBl");
var txtCj_Test_Bl=document .getElementById ("txtSycjBl");
var txtCj_Jm_Bl=document .getElementById ("txtJmcjBl");
if(txtKSTime.value.length==0)
{
alert("请选择考试时间!");
return false;
}
else
{
if(txtKSTime.value>timeNow)
{
alert("所选择的考试时间不能大于当前时间!");
return false;
}
}
if(ddlstGradeLx.selectedIndex==0)
{
alert("请选择保存总评成绩格式!");
return false;
}
if(txtCj_Ps_Bl.value.length==0&&txtCj_Test_Bl.value.length==0&&txtCj_Jm_Bl.value.length==0)
{
alert("比例设置不能为空!");
return false;
}
var btnSave=document .getElementById ("btnSubmit");
var flag=0;
var flagCj=0;
var flagZCj=0;
var txtKSTime=document .getElementById ("txtKssj");
var ddlstGradeLx=document .getElementById ("ddlstGradeLx");
var pscjBl=document .getElementById ("txtPscjBl");
var sycjBl=document .getElementById ("txtSycjBl");
var jmcjBl=document .getElementById ("txtJmcjBl");
var array=new Array();
for(m=0;m<gv.rows.length;m++)
{
for(n=0;n<4;n++)
{
array[m,n]=0;
}
}
if(pscjBl.value.length>0&& sycjBl.value.length>0&&jmcjBl.value.length>0)
{
pBl=parseInt(pscjBl.value);
sBl=parseInt(sycjBl.value);
jBl=parseInt(jmcjBl.value);
if((pBl+sBl+jBl)!=100)
{
alert ("比例之和必须为100%");
return false ;
}
else
{
for( i=1;i<gv.rows.length;i++)
{
var score_ZCj=document.getElementById(gv.rows[i].cells[5].firstChild.id).value;
if(score_ZCj==""||score_ZCj==null)
{
flagZCj=1;
}
}
if(flagZCj==0)
{
for( i=1;i<gv.rows.length;i++)
{
for(m=0;m<gv.rows.length;m++)
{
for(n=0;n<4;n++)
{
array[m,n]=0;
}
}
var txtCj_Ps=document.getElementById(gv.rows[i].cells[2].firstChild.id)
var txtCj_Test=document.getElementById(gv.rows[i].cells[3].firstChild.id)
var txtCj_Jm=document.getElementById(gv.rows[i].cells[4].firstChild.id)
var txtCj_Total=document.getElementById(gv.rows[i].cells[5].firstChild.id)
var score1=txtCj_Ps.value;
var score2=txtCj_Test.value;
var score3=txtCj_Jm.value;
var score4=txtCj_Total.value;
if(score1==""||score1==null)
{
score1=0;
}
if(score2==""||score2==null)
{
score2=0;
}
if(score3==""||score3==null)
{
score3=0;
}
if(score4==""||score4==null)
{
flagZCj=1;
}
txtCj_Ps.style.color = "black";
txtCj_Test.style.color = "black";
txtCj_Jm.style.color = "black";
txtCj_Total.style.color = "black";
if(score1<0||score1>100||score2<0||score2>100||score3<0||score3>100||score4<-3||score4>100)
{
if(score1<0||score1>100)
{
array[i,0]=1;
flag=1;
}
if(score2<0||score2>100)
{
array[i,1]=2;
flag=1;
}
if(score3<0||score3>100)
{
array[i,2]=3;
flag=1;
}
if(score4<-3||score4>100)
{
array[i,3]=4;
flag=1;
}
for(var j=0;j<4;j++)
{
if(array[i,j]==1)
{
txtCj_Ps.style.color = "red";
}
if(array[i,j]==2)
{
txtCj_Test.style.color = "red";
}
if(array[i,j]==3)
{
txtCj_Jm.style.color = "red";
}
if(array[i,j]==4)
{
txtCj_Total.style.color = "red";
}
}
}
else
{
if(score1!=0||score2!=0||score3!=0)
{
if(score1>=0&&score2>=0&&score3>=0&&score4>=0)
{
var ZCj=(parseInt(score1)*pBl +parseInt(score2)*sBl +parseInt(score3)*jBl)/100;
var Cj=parseInt(score4);
if(Math.abs(ZCj-Cj)>1)
{
txtCj_Ps.style.color = "red";
txtCj_Test.style.color = "red";
txtCj_Jm.style.color = "red";
txtCj_Total.style.color = "red";
flagCj=1;
}
else
{
txtCj_Ps.style.color = "black";
txtCj_Test.style.color = "black";
txtCj_Jm.style.color = "black";
txtCj_Total.style.color = "black";
}
}
else
{
if(score4==-1||score4==-2||score4==-3)
{
txtCj_Total.style.color = "black";
}
}
}
}
}
}
if(flagZCj==1)
{
alert("总成绩不能为空,可以为零!");
return false;
}
if(flag==1||flagCj==1)
{
if(flag==1)
{
btnSave.disabled =true ;
alert("成绩数值必须在0到100之间!总成绩可以为-1,-2,-3!不合格的成绩将会以红色字体显示!");
}
if(flagCj==1)
{
btnSave.disabled =true ;
alert ("平时成绩*比例+实验成绩*比例+卷面成绩*比例之和不等于总成绩!将会以红色字体显示不正确的成绩!");
}
}
else
{
btnSave.disabled =false;
alert ("可以录入,点击提交按钮录入成绩!");
}
}
}
}