How can I get the return value from dataValidate() and apply it to
if (isset($_POST['save'] {
//here I want to code
if passed validation, then go ahead to process data save. otherwise, do not go into this save process.
My problem is that even validation is not passed, it still go through the save process.
What should I do?
Thanks a lot! You are a big helper!
}
here is my dataValidate() function:
function dataValidate()
{
//check whether task name and task title has value before save
if (document.screenform.txtTaskname.value.length ==0 ){
alert ("You must enter taskname!");
document.screenform.txtTaskname.focus();
return;
}
if (document.screenform.txtCcrTitle.value.length ==0){
alert ("You must enter task title!");
document.screenform.txtCcrTitle.focus();
return;
}
document.screenform.submit();
}
here is my save button HTML:
<input type="Submit" name="save" value="Submit data" onclick="dataValidate()">
Here are my code for when save button submitted: They basically get the value from HTML form and insert into database and then tell user that data has been saved...
if (isset($REQUEST["save"]))
{
echo " save button has been submitted";
$db = mysql_connect("anansi.nesdis.noaa.gov","hlu","flozz34");
mysql_select_db("TES3devo",$db);
$id=$POST['txtCcrId'];
$title =$POST['txtCcrTitle'];
$taskname =$POST['txtTaskname'];
$product=$POST['selProduct'];
$initiator =$POST['txtInitiator'];
$initPriority =$POST['selInitPriority'];
$Palpriority =$POST['selPALPriority'];
$status=$POST['selStatus'];
$totalHours= $POST['txtTotalHours'];
$remainHours =$_POST['txtRemainingHours'];
if ($HTTP_POST_VARS['chkProDesc'] =="1"){
$ProDesc =1;
//echo "PDD check box is". $ProDesc;
}
else{
$ProDesc =0;
//echo "PDD check box is". $ProDesc;
}
if ($HTTP_POST_VARS['chkInterControl'] =="1"){
$InterControl =1;
//echo "IC check box is". $InterControl;
}
else{
$InterControl =0;
//echo "IC check box is" .$InterControl;
}
if ($HTTP_POST_VARS['chkSysDesc'] =="1"){
$SysDesc =1;
//echo "check box is" .$SysDesc;
}
else{
$SysDesc =0;
//echo "check box is". $SysDesc;
}
if ($HTTP_POST_VARS['chkUserManu'] =="1"){
$UserManu =1;
//echo "check box is" .$UserManu;
}
else{
$UserManu =0;
//echo "check box is". $UserManu;
}
if ($HTTP_POST_VARS['chkMainManu'] =="1"){
$MainManu =1;
//echo "check box is" .$MainManu;
}
else{
$MainManu =0;
//echo "check box is" .$MainManu;
}
if ($HTTP_POST_VARS['chkOperManu'] =="1"){
$OperManu =1;
//echo "check box is" .$OperManu;
}
else{
$OperManu =0;
//echo "check box is" .$OperManu;
}
if ($HTTP_POST_VARS['chkOperEvent'] =="1"){
$OperEvent =1;
//echo "check box is". $OperEvent;
}
else{
$OperEvent =0;
//echo "check box is" .$OperEvent;
}
if ($HTTP_POST_VARS['chkOthers'] =="1"){
$Others =1;
//echo "check box is" .$Others;
}
else{
$Others =0;
//echo "check box is". $Others;
}
$descTask =$POST['descTask'];
$ReasonChange =$POST['ReasonChange'];
$EffectChange=$POST['EffectChange'];
$alternatives =$POST['alternatives'];
$ProblemRes = $POST['ProblemRes'];
$ImpleRequ =$POST['ImpleRequ'];
$AssignPersonnel =$POST['AssignPersonnel'];
$PalDispo =$POST['PalDispo'];
$FormDate =$POST['FormDate'];
$DispoDate =$POST['DispoDate'];
$StartDate =$POST['StartDate'];
$closeDate =$POST['closeDate'];
$sql = "INSERT INTO TES
values($id,'$title','$taskname','','$product','$initiator','$initPriority','$Palpriority','$
status',$totalHours,$remainHours,
$ProDesc,$InterControl,$SysDesc,$UserManu,$MainManu,$OperManu,$OperEvent,$Others,'$descTask'
,'$ReasonChange',
'$EffectChange','$alternatives',
'$ProblemRes','$ImpleRequ','$AssignPersonnel',
'$PalDispo','$StartDate','$DispoDate',
'$FormDate','$closeDate')";
$result = mysql_query($sql,$db);
echo "Thank you! Information entered.\n";
//document.screenform.action="search_hlu.php";
}