Help Simplifying Javascript for a repetitive code! - Please
I have made a form with the purpose of having multiple dropdowns for inserting an 'ID number' which would then populate the following text fields: 'description,' 'quantity,' and a 'unit.'
This form is working perfectly as intended but I was wondering if there was a better way to code it.
There is a very repetitive code which is needed for assigning the dropdowns to the corresponding fields:
function SetFieldValues1(cID1) {
this.getField("Desc1").value = DeptData[cID1].description;
this.getField("Quan1").value = DeptData[cID1].quantity;
this.getField("Unit1").value = DeptData[cID1].unit;
}
function SetFieldValues2(cID2) {
this.getField("Desc2").value = DeptData[cID2].description;
this.getField("Quan2").value = DeptData[cID2].quantity;
this.getField("Unit2").value = DeptData[cID2].unit;,Etc....
and this is linked to the dropdowns as such:
(ID1)Custom Keystroke Script:
if( event.willCommit )
{
if(event.value == " ")
this.resetForm(["Desc1","Quan1","Unit1"]);
else
SetFieldValues1(event.value);
}(ID2)Custom Keystroke Script:
if( event.willCommit )
{
if(event.value == " ")
this.resetForm(["Desc2","Quan2","Unit2"]);
else
SetFieldValues2(event.value);
},Etc....
Is there a simpler way to do this?
Any help would be amazing
Thank you all in advance!
-Flynn Hammonds
