Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

How to get a date field to be blank if option 1 is selected from a dropdown but populate if another option is selected

$
0
0

Hi,

I currently have some code which populates a datefield depending on which option is used from a drop down. However what i would like to be able to do is if option 1 is selected from the dropdown then the date field should be left blank otherwise a certain number of days should be added to the current date and populate date field accordingly. I have tried to create a variable e.g  var blank = " " however as expected this does not work as the date field does not like string. Please see code below which is working. As I could not get if type ==1 to return blank i just added 365 days so it does not impact the case for now. However ideally i would like to have the field to be blank if 1.

Any ideas on how my code could be amended to get this to work.

var CRM_FORM_TYPE_CREATE = "1";
var DUE;
var TODAY  = new Date();
var days;
var ttype = crmForm.all.kf_servicetype.DataValue;
if (ttype==1)
  {
   var days = 365;
  }
  else if (ttype==2)
        {
     var days = 365;
    }
  else if (ttype==3)
        {
     var days = 30;
    }
  else if (ttype==4)
        {
     var days = 7;
    }
      else { return(0);
  }

DUE = new Date(crmForm.all.kf_lastvisitcompleted.DataValue.getTime() + (days*24*60*60*1000));
crmForm.all.kf_visitdue.DataValue = DUE;

crmForm.all.kf_visitdue.ForceSubmit = true;

Thank you

Kully


Viewing all articles
Browse latest Browse all 1000

Trending Articles