File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes 2 functions at onsubmit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "2 functions at onsubmit" Watch "2 functions at onsubmit" New topic
Author

2 functions at onsubmit

vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
well your one has return is inside an if statement.

Eric
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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

Joined: Jun 02, 2006
Posts: 95
Solved the problem. Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 functions at onsubmit