Forum Moderators: open

Message Too Old, No Replies

Problem with the "return false" statement in a JavaScript Function

What is the reason for this? :-(

         

skyzhere

3:08 pm on Aug 2, 2006 (gmt 0)

10+ Year Member



Hi everyone,

I am facing a problem with the javascript code that i have written...The code is pasted below..

The link in my jsp file is as below:

<a class="stdlink" href="javascript:downloadVolumeReport();"><img src="images/button_download.gif" alt="Download" border="0"></a>

------------------------------- Javascript Codes are as below
function downloadVolumeReport()
{
if ( doDateCheck() )
{
var frm_nm = document.volume_report ;
frm_nm.form_action.value="generate_volume_report" ;
frm_nm.action = "finance_rep" ;
frm_nm.method = "post";
frm_nm.submit();
}
else
{
return false;
}
}
------ The function doDateCheck is in other .js file....

function doDateCheck()
{
if ( Date.parse(document.volume_report.FromDate.value) > Date.parse(document.volume_report.ToDate.value) )
{
alert("To Date must be Later than From Date.!\n\n Please Select the date range again.");
document.volume_report.FromDate.focus();
return false;
}
return true;
}
----------------

Now the problem is that if I select the dates in the form such that the "FromDate" is Greater then the "ToDate" and click on submit then a blank page is displayed with false printed on it. But if i remove the false word then the blank page with teh false word is not dispalyed...

As far as i know if a javascript function validates the form data and finds a problem then to avoid displaying the next page we use "return false" statement......

But i am not able to understand why this is happening.....

Guyz...Please help me in resolving this as it is reallly hampering the progress of my work...

Thanks in advance

Fotiman

5:21 pm on Aug 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try moving your javascript call to the "onclick" handler instead of in the href value.

<a class="stdlink" href="#" onclick="return downloadVolumeReport();"><img src="images/button_download.gif" alt="Download" border="0"></a>

skyzhere

9:01 am on Aug 8, 2006 (gmt 0)

10+ Year Member



Thanks Fotiman....It worked..

Can u tell me the reason behinde that?..It will add to my knowledge Base..

Thanks a lot again for your timely help..

Fotiman

1:47 pm on Aug 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The href attribute specifies the location of a Web resource, thus defining a link between the current element (the source anchor) and the destination anchor defined by this attribute.

By moving the javascript to the event handler, the href value will not be called if the onclick returns false.