• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Help, with multiple prefill data from dropdown field form.

Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

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 works perfectly with this code (Custom Keystroke Script) for all of the dropdown labelled: "ID1" - "ID40"

var idNumber = event.target.name.replace("ID", "");
if( event.willCommit )
{
   if(event.value == " "||event.value == ""||event.value == "undefined")
this.resetForm(["Desc"+idNumber,"No"+idNumber,"Unit"+idNumber,"Price"+idNumber]);
   else
     SetFieldValues(event.value, idNumber);
}

And a 'Document Javascript' named "SetFeildValues" with the following code:

// Place all prepopulation data into a single data structure
  var DeptData = {
        // HEADINGS***********************************
    1000:{
      description: " MAIN HOUSE ROOFING",
      quantity: "",
      unit: "",
      price: ""
    },
    1001:{
      description: "CARPORT",
      quantity: "",
      unit: "",
      price: ""
    },
    // ROOFINGS
    BC:{
      description: "BUILDING CERTIFICATION: All Building Approvals And Certification Upon Completion Of Works Following QBCC And Local Council Specifications.",
      quantity: "1",
      unit: "each",
      price: ""
    },
    1:{
      description: "Supply & Fit Colorbond Roof Sheets, Including, Valley Irons, Barge Roll Flashings And Cappingā€™s As Required. Profile: Custom Orb.",
      quantity: "",
      unit: "sqm",
      price: ""
    },
    2:{
      description: "RUBBISH REMOVAL: Remove, Recycle And Dispose Of Existing Roofing And Debris.",
      quantity: "1",
      unit: "each",
      price: "500"
    },
    3:{
      description: "Remove, Supply And Install Metal Roof Battens To Correct Spacings to Facilitate Works.",
      quantity: "",
      unit: "lm",
      price: ""
    },
    4:{
      description: "Supply and Install Sarking to Entire Roof During Roof Replacement.",
      quantity: "",
      unit: "sqm",
      price: ""
    },
    5:{
      description: "GUTTERS: Remove And Replace Gutter To Match Existing As Close As Possible.",
      quantity: "",
      unit: "lm",
      price: ""
    },
    6:{
      description: "Trestle And Plank Hire To Facilitate Gutter Replacement.",
      quantity: "1",
      unit: "each",
      price: ""
    },
    7:{
      description: "WHIRLY BIRD: Remove, Supply And Replace Whirlybirds To Match Existing As Close As Possible.",
      quantity: "1",
      unit: "each",
      price: ""
    },
    8:{
      description: "AERIAL REFIT: Remove And Refit Aerial/Antenna (Including Reconnection).",
      quantity: "1",
      unit: "each",
      price: ""
    },
    9:{
      description: "Toilet - Hire Of Chemical Site Toilet, Cleaned Out Once A Week. Including Pick Up And Drop Off",
      quantity: "1",
      unit: "each",
      price: ""
    },
    10:{
      description: "QBCC Home Warranty Insurance As Per Council And QBCC GUIDELINE: Prepare, Purchase And Issue Required QBCC Home Warranty Insurance.",
      quantity: "1",
      unit: "",
      price: ""
    }
  };


function SetFieldValues(cID, idx) {
    this.getField("Desc"+(parseInt(idx))).value = DeptData[cID].description;
    this.getField("No"+idx).value = DeptData[cID].quantity;
    this.getField("Unit"+idx).value = DeptData[cID].unit;
    this.getField("Price"+idx).value = DeptData[cID].price;
}

 

All of this works perfectly!!!

But when I try to make a section for making a sequence for the various totals:

"Subtotal," "20% Margin," "Subtotal w/ "Margin," "Warranty," "Total, Gst," "Total w/ Gst"

with each title in the "description" columns using the following code added into the previous 'Document Javascript' named "SetFeildValues":

        //***********************************TOTAL**************************************************
    0:{
      description: "SUBTOTAL",
      description2: "20% BUILDERS MARGIN",
      description3: "SUBTOTAL W/ MARGIN",
      description4: "QBCC Home Warranty Insurance",
      description5: "TOTAL",
      description6: "GST",
      description7: "TOTAL W/ GST",
      description8: "******************************************************************************************************************" 
  }


function SetFieldValues(cID, idx) {
    this.getField("Desc"+(parseInt(idx))).value = DeptData[cID].description;
    this.getField("Desc"+(parseInt(idx)+1)).value = DeptData[cID].description2;
    this.getField("Desc"+(parseInt(idx)+2)).value = DeptData[cID].description3;
    this.getField("Desc"+(parseInt(idx)+3)).value = DeptData[cID].description4;
    this.getField("Desc"+(parseInt(idx)+4)).value = DeptData[cID].description5;
    this.getField("Desc"+(parseInt(idx)+5)).value = DeptData[cID].description6;
    this.getField("Desc"+(parseInt(idx)+6)).value = DeptData[cID].description7;
    this.getField("Desc"+(parseInt(idx)+7)).value = DeptData[cID].description8;

Now when I use any of the previous dropdown titles it fills in the fields underneath with "undefined" 

Is there a way to make it so that any unspecified field is left as is?

 

Any help would be amazing, thank you all for your help in advance!

 

TOPICS
General troubleshooting , How to , JavaScript , PDF forms

Views

3.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Here is a photo of what is happening

 

Screen Shot 2021-02-16 at 4.30.36 pm.pngScreen Shot 2021-02-16 at 4.30.56 pm.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

You will get undefined because description2, description3, and so on are not defined for this entry.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Thanks for the reply!
I am aware that it is happening because they are undefined in the "SetFeildValues" section. I could set the values to nothing but this would just remove the descriptions of the items below.

I was wondering if there would be any way that I could have the single-lined description not change any of the descriptions below them. 

 

Thank you again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

LATEST

Don't change the field when the value is undefined.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines