in my application refresh ,save&exit and print butons are there
when i click refresh ,save&exit and print butons when certains conditions met this checkLoadType() should call;
but WHEN i click save&exit alert message coming twice because i have written this checkLoadType() in validate() and setAction(obj);(but i want to fire once only)
validate() in form tag also calling so i want to restrict validate() when i click save&exit
function setAction(obj)
{
if(!checkLoadType())
return false;
if (obj=="SNE")
{
document.getElementById("N
extOperati
on").value
="Submit";
document.getElementById("i
sSave").va
lue="true"
;
document.forms[0].submit()
;
return true;
}
}
function validate()
{
if(!checkLoadType())
return false;
if('MHBL'=='FCR' && 'F' == 'F' && document.getElementById("N
extOperati
on").value
== 'Packs')
{
alert('Cannot enter item details for FCL shipment');
return false;
}
}
function checkLoadType()
{
var ary=document.getElementsBy
TagName("i
nput");
var str="";
for (var i=0;i<ary.length;i++){
if (ary[i].type.toLowerCase()
=="checkbo
x" && ary[i].checked==true){
var obj=ary[i].parentNode;
for(var j=0;j<15;j++){
obj=obj.nextSibling;
}
var newStr=obj.innerText;
str = str+newStr+',';
}
}
var temp = str.split(',')
var code = temp[0]
for(i=0; i <temp.length-1;i++)
{
if(temp[i] != code)
{
alert("Shipments of either LCL or FCL type can only be consolidted");
return false;
}
}
return true;
}
<form method="post" action="FCRController" onSubmit='return validate()'>
<input type="submit" name="SaveAndExit" id="SaveAndExit" value="Save & Exit" class='input' TABINDEX="101" onClick = "setAction('SNE')" >
<input type="submit" name="Refresh" id="Refresh" value="Refresh" class='input' TABINDEX="100" >
<input type="submit" name="ENTER" id="ENTER" value="ENTER" class='input' TABINDEX="100" >
Start Free Trial