• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 functions at onsubmit

 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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( )">
[ July 18, 2006: Message edited by: Bear Bibeault ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well your one has return is inside an if statement.

Eric
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well your one has return is inside an if statement.

I'm sorry but i dont understand. what must i do to the code.

another option, is it possible to join the code like the below. 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>
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the problem. Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic