If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Problem with Java script

Started by vmaharshi, 04 Oct 2007 09:25:37 AM

Previous topic - Next topic

vmaharshi

Hi,
  I am trying to populate the previous date by using the following javascript.
<script>

//Javascript does not contain a method for day addition or subtraction :(
function subtractDay ()
{
  var dtToday = new Date();
  var strDate, strYear, strMonth, strDay, intMonth;

  //Change the month to the previous month if necessary
  if (!(dtToday.getDate()-1))
    intMonth = dtToday.getMonth()-1;
  else
    intMonth = dtToday.getMonth();

  //Change the year to the previous year if necessary
  if (intMonth<0)
  {
    strMonth = "12-";
    strYear = (dtToday.getUTCFullYear()-1)+"-";
  }
  else
  {
    strMonth = intMonth+1+"-";
    strYear = dtToday.getUTCFullYear()+"-";
  }

  //If at the first day of a month, find the last day of the previous month
  if (dtToday.getDate()==1)
  {
    switch (strMonth)
    {
      case "4-" :
      case "6-" :
      case "9-" :
      case "11-": strDay = "30"; break
      case "2-" : (!(parseInt(strYear)%4)) ? strDay=29 : strDay=28; break
      default : strDay = "31";
    }
  }
  else
    strDay = dtToday.getDate()-1+"";

  return strYear+strMonth+strDay;
}

//Place list of date prompts to be dynamic here.
pickerControlXXXX = new CDatePicker(document.forms["formWarpRequest"].elements["p_YYYY"], document.forms["formWarpRequest"].elements["_oChoiceXXXX"], document.forms["formWarpRequest"].elements["_oChoiceXXXX"], document.getElementById('dialogDatePickerXXXX'), 'XXXX', subtractDay (), 1, 0, '',0, 0, '', '', true, 'XML', document.formWarpRequest.imgTestXXXX);
</script>



The code is working fine if i select UI of the prompt as calendar. But it is not working if i select the UI as edit box.

Please help me on this.

micato99

Hi,

Try this. In this example you just have to specify parameter name (date_from in this case)....
This script will go trough all controls on prompt page and find one which use correct parameter.  :)

<script>
var cntlName;
for( var i=0; i<preProcessControlArray.length; i++){
   var strDate;
   var mydate= new Date();
   mydate.setDate(mydate.getDate()-1);

   var theyear=mydate.getFullYear();
   var themonth=mydate.getMonth()+1;
   var theyesterday=mydate.getDate();

     strDate = theyear + "-" + themonth + "-" + theyesterday;
   
   cntlName = eval(preProcessControlArray);
   if (cntlName.m_oSubmit.name.toLowerCase() == 'p_date_from' ){
   cntlName.m_oEditBox.value = cntlName.m_oEditBox.value = strDate; 
   eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
   }   
  }
</script>