This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 functions at onsubmit
 
Similar Threads
problem in getting date and time in textbox
Newbie need help with textfield value.
Unsure how to handle advance date calculations
validate jvascript
Check if an email-adress is valid with javascript