I have a button on a form that is activated when I want to save the form. I have an event that is like this:
private void btnaddheader_Click(object sender, System.EventArgs e)
{
//Code that is activated when button is clicked
}
How do I include a javascript for client side validation in this code?
I had a client side script below for traditional onclick for html button element:
function addpart(formname)
{
var msg = "Error! Need the following entries:";
var flag=true;
if (document.nido_new.txtorde
rfulfilmen
tprefix.va
lue == "" || document.nido_new.txtorder
fulfilment
id.value == "" || document.nido_new.txtcallt
imehh.valu
e == "" || document.nido_new.txtcallt
imemm.valu
e == "")
{
if (document.nido_new.txtorde
rfulfilmen
tprefix.va
lue == "")
msg = msg + String.fromCharCode(13) + "* order fulfilment prefix";
if (document.nido_new.txtorde
rfulfilmen
tid.value == "")
msg = msg + String.fromCharCode(13) + "* order fulfilement number";
if (document.nido_new.txtcall
timehh.val
ue == "" || document.nido_new.txtcallt
imemm.valu
e == "")
msg = msg + String.fromCharCode(13) + "* call time";
flag=false;
}
var myform = document.nido_new
ctrlDay = "selcalldatedd"
ctrlMonth = "selcalldatemm"
ctrlYear = "selcalldateyy"
if(!(Checkdateb4submit(myf
orm[ctrlDa
y],myform[
ctrlMonth]
,myform[ct
rlYear])))
{
msg = msg + String.fromCharCode(13) + "* call date wrong";
//alert("Please key in correct call date");
document.nido_new.selcalld
atedd.focu
s();
flag=false;
}
ctrlDay1 = "selapptdatedd"
ctrlMonth1 = "selapptdatemm"
ctrlYear1 = "selapptdateyy"
if(!(Checkdateb4submit(myf
orm[ctrlDa
y1],myform
[ctrlMonth
1],myform[
ctrlYear1]
)))
{
msg = msg + String.fromCharCode(13) + "* appointment date wrong";
//alert("Please key in correct appointment date");
document.nido_new.selapptd
atedd .focus();
flag=false;
}
ctrlhh = "txtcalltimehh"
if (!(Checkhh(myform[ctrlhh])
))
{
msg = msg + String.fromCharCode(13) + "* call time hh between 0 and 23";
//alert("Please enter an integer between 0 and 23");
document.nido_new.txtcallt
imehh.focu
s();
flag=false;
}
ctrlmm = "txtcalltimemm"
if (!(Checkmm(myform[ctrlmm])
))
{
msg = msg + String.fromCharCode(13) + "* call time mm between 0 and 59";
//alert("Please enter an integer between 0 and 59");
document.nido_new.txtcallt
imemm.focu
s();
flag=false;
}
ctrlhh1="txtappttimehh"
if (!(Checkhh(myform[ctrlhh1]
)))
{
msg = msg + String.fromCharCode(13) + "* appointment time hh between 0 and 23";
//alert("Please enter an integer between 0 and 23");
document.nido_new.txtapptt
imehh.focu
s();
flag=false;
}
ctrlmm1="txtappttimemm"
if (!(Checkmm(myform[ctrlmm1]
)))
{
msg = msg + String.fromCharCode(13) + "* appointment time mm between 0 and 59";
//alert("Please enter an integer between 0 and 23");
document.nido_new.txtapptt
imemm.focu
s();
flag=false;
}
if (flag==false)
{
alert(msg);
}
else
{
document.nido_new.action = 'nido_new_ins.asp';
document.nido_new.submit()
;
}
}