Click to See Complete Forum and Search --> : urgent : 2 functions at onsubmit


lvsaint
07-18-2006, 12:25 PM
Hi, but how do run 2 funtions at onsubmit. They are both javascript. Here are my scripts

<script type="text/javascript">

function checkDate(nForm){

var sDate = nForm['dc1'].value;
sDate = sDate.split('-');
sDate = new Date(sDate[2],sDate[1]-1,sDate[0])
var eDate = nForm['dc2'].value;
eDate = eDate.split('-');
eDate = new Date(eDate[2],eDate[1]-1,eDate[0])
nForm['daysApart'].value = (eDate-sDate)/86400000;
nForm['hiddenElmName'].value=nForm['daysApart'].value
alert(nForm['daysApart'].value);

return true;
}

</script>


<script language="JavaScript">
function validate_form ( )
{
valid = true;

if ( document.leaveform.select.selectedIndex == 0 )
{
alert ( "Please select leave type" );
valid = false;
document.leaveform.select.focus();
return valid;
}

}
</script>

I have tried both the following. it doesnt work.

<form id="form1" name="leaveform" method="post" action="checkleave.jsp" onSubmit="return (checkDate(this) && validate_form( ));">

<form id="form1" name="leaveform" method="post" action="checkleave.jsp" onSubmit="return checkDate(this) && validate_form( )">

skilled1
07-18-2006, 12:33 PM
why dont you just combine the codes, alot of times the problem is one is fighting with the other.

lvsaint
07-18-2006, 12:36 PM
How do i go about combining the codes...

I tried this but it does not work .

<script type="text/javascript">

function checkDate(nForm){

var sDate = nForm['dc1'].value;
sDate = sDate.split('-');
sDate = new Date(sDate[2],sDate[1]-1,sDate[0])
var eDate = nForm['dc2'].value;
eDate = eDate.split('-');
eDate = new Date(eDate[2],eDate[1]-1,eDate[0])
nForm['daysApart'].value = (eDate-sDate)/86400000;
nForm['hiddenElmName'].value=nForm['daysApart'].value
alert(nForm['daysApart'].value);

return true;



valid = true;

if ( document.leaveform.select.selectedIndex == 0 )
{
alert ( "Please select leave type" );
valid = false;
document.leaveform.select.focus();
return valid;
}

}
</script>

slaughters
07-18-2006, 01:01 PM
function SubmitMe(nForm) {

if (Check_Date(nForm) ) {

if (validate_form(nForm) ) {
nForm.submit();
} else {
alert ("The form is BOGUS MAN !");
}

} else {
alert ("The dates are BOGUS MAN !");
}

}Remove the OnSubmit stuff and instead of using a submit button just use a botton with an onClick="SubmitMe(form1)"

OR - simply put a call to validate_form at the end of the Check_Date function

OR - call validate_form first and at the end of it call the Check_Date function

OR - as skilled1 said combine the two functions

OR ....

lvsaint
07-18-2006, 01:32 PM
Problem solved, thank you