Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
7 years ago

Try to add dynamic value into drop down list

Hello friends ,

I am try to add dynamic value in drop down list but get below error message 

 Please help me, my javascript code is below, code is triger on form populated event. 

var startDate=0,finishdate=0;
function pad(x) {
return (x < 10) ? "0" + x : "" + x;
}
function DateFormate(dateFormate) {
var myDate = new Date(dateFormate);
var dateString = myDate.getFullYear()+ "-";
startDate=myDate.getFullYear();
dateString += pad(myDate.getMonth() + 1) + "-";
dateString += pad(myDate.getDate());

return dateString;
}
function DateFormate1(dateFormate) {
var myDate = new Date(dateFormate);
var dateString = myDate.getFullYear()+ "-";
finishdate=myDate.getFullYear();
dateString += pad(myDate.getMonth() + 1) + "-";
dateString += pad(myDate.getDate());

return dateString;
}
var inn=new Innovator();
var Project=inn.newItem();
Project.loadAML("<Item type='project' select='id,project_number,date_start_target,date_due_target' action='get'>"+
"<project_number condition='eq'>"+document.thisItem.getProperty("project_number")+"</project_number>"+
"</Item>"
)
var projectR=Project.apply();
DateFormate(projectR.getProperty("date_start_target"));
DateFormate1(projectR.getProperty("date_due_target"));
var difBetweenstartandfin=parseFloat(finishdate)-parseFloat(startDate)

//var selectObj = document.all.from_year;

//var selectObj =getFieldByName("from_year")

I tried one line statement of code from both marked line,but get every time same error message.


var opt = document.createElement("OPTION");
//alert(opt)
selectObj.options.add(opt); // Error is coming on this point.


//selectObj.add(opt)
for(var i=0;i<=difBetweenstartandfin;i++)
{
startDate=startDate+i;
//alert(startDate)


opt.innerText = startDate;
opt.value = startDate;

}

Thank in advance ,

Ashok Kumar Yadav

2 Replies

  • hello Ashok Kumar Yadav

    do you still have problem ?

    • angela's avatar
      angela
      Catalyst II

      Handling dropdowns depends on your Aras version. But in general you cannot access dropdowns with getFieldByName. And document.createElement would only work with native html dropdowns, but it seems you want to use the Aras dropdown. I once created this very helpful community project: https://github.com/AngelaIp/cui-select-starting-page . Take a look at the _onLoad Method. The handling of dropdowns is the key feature of this project.