Jump to content
  • 0

Calculated Field based on selection in dropdown list


rollandpate
 Share

Question

I am trying to populate a field on my webform based on the selection from the Dropdown list of another field on the form. For example: If I select "1st Place" from the Dropdown list I would like the Points field to be populated with the value of 4.

I am using the following JavaScript in the Footer of the Submission Form.

<SCRIPT LANGUAGE="JavaScript">

function getPts()
{ 
   /* Retrieve the value of the field Cookoff_Result_Place and store in a variable 'Place' */
  var Place = document.getElementById("InsertRecordCookoff_Result_Place").value;

  switch (Place)
  {
    case '1': case '11': case '14': case '17': case '20': document.getElementById("InsertRecordCookoff_Result_Points").value=4;
    break;
    case '2': case '12': case '15': case '18': case '21': document.getElementById("InsertRecordCookoff_Result_Points").value=3;
    break;
    case '3': case '13': case '16': case '19': case '22': document.getElementById("InsertRecordCookoff_Result_Points").value=2;
    break;
    default: document.getElementById("InsertRecordCookoff_Result_Points").value=1
  }
}

/* On submitting the webform, the function getPts is executed */
document.getElementById("caspioform").onsubmit=getPts;
</SCRIPT>

Everything works while I am in Caspio but when I deploy the form to my website it stops populating the Points field. I'm not sure what needs to be changed to get it to work from my website.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Most possible problem is the line of code below if you have more than one DataPage deployed on your website:

document.getElementById("caspioform").onsubmit=getPts;

In this case, you will need to encapsulate each DataPage in a Div with an assigned ID and then call the ID of that DataPage on submit function. Example:

DataPage hearer:

DataPage footer:

Script:

document.getElementById("DP1").onsubmit=getPts;

Let me know if this fixes the issue.

Best,

Bahar M.

Link to comment
Share on other sites

  • 0

As of July 12, 2018, Caspio introduced new features which you can find here: https://howto.caspio.com/release-notes/caspio-bridge-13-0/

This release includes a new feature, Calculated Values in Submission Forms.  This allows you to generate calculations which you can use for your Dropdown list

Check these videos for more information:

 

I hope this helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...