Friday, February 26, 2010

JavaScript for Date Validation

I keep receiving a lot of requests for Date Validation Javascript, thought I would share the same. Though this information is available on millions of sites, thought this could be of some use to all those who use this blog often.

Step 1: Drag 2 Date Prompts into the prompt page

Step 2: Name the Date Prompts as FromDate and ToDate

Step 3: Drag an HTML Item below the prompts and include the below script:


<script type="text/javascript">
function validateDate()
{
var fW = (typeof getFormWarpRequest == "function" ?getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined)
{ fW = ( formWarpRequest_THIS_ ?formWarpRequest_THIS_ : formWarpRequest_NS_ );
}

var FromDate = fW.txtDateFromDate.value;
var ToDate = fW.txtDateToDate.value;

if(FromDate > ToDate)
{alert('From Date is greater than To Date');}
else
{promptAction('finish');}
}
</script>



Step 4: Drag another HTML Item to create the prompt button. The onclick event of the button will trigger the date validation function.


<input type=button onclick='validateDate()' value='Finish'>


Step 5: Drag a Prompt Button - Finish to enable the submission of the prompt page and hide the button by seting the height and width to 0px.

Note: This technique uses JavaScript against underlying report objects in a IBM Cognos 8 BI report. For this reason, there is no guarantee that reports created using this technique will migrate or upgrade successfully to future versions without requiring modifications. Any such modifications are the responsibility of the report designer.

5 comments:

Anonymous said...

This script is not working.

Anonymous said...

Sorry it's working if i change the prompt to editbox. But how to get this working for calendar coontrol?

Zephyr said...

This link should help you out -

http://www-01.ibm.com/support/docview.wss?uid=swg21340322

This helps you retrieve the date from the Calendar control and then you should be able to perform your validation.

Anonymous said...

This javascript works smoothly...thanks a lot for this post

Anonymous said...

this script works when from date is changed if you try to change to date then script does not work
say example if you enter from date 26/10/2014 to 27/10/2012 then report gets executed which is not correct.