Jump to content

JavaScript - Add Value from Virtual Field


Recommended Posts

Hello,

I am attempting to create an option on a submission form that will allow me to add a value to a dropdown list of values if that particular value is not currently in the dropdown. I know that you can do this via:

https://howto.caspio.com/tech-tips-and-articles/automatically-add-options-to-dropdowns-and-listboxes/

But it resets all the values and the flow is not ideal. I have 3 dropdowns that each have "add new" virtual field checkbox. So if the value is not in the dropbox, I would click the corresponding "Add New" and then type out the new value. (see the id's for each via picture)

Here is my current code:
- Placed in footer (though I tried in HTML block placed last on the form, as well)

<script type="text/javascript">
function d_text()

{

document.getElementById("cbParamVirtual1").disabled = true;

document.getElementById("cbParamVirtual3").disabled = true;

document.getElementById("cbParamVirtual5").disabled = true;

}

function f_boxcheck()

{

if(document.getElementById("cbParamVirtual2").checked){

document.getElementById("cbParamVirtual1").disabled = false;

}else {document.getElementById("cbParamVirtual1").disabled = true;}

}

function s_boxcheck()

{

if(document.getElementById("cbParamVirtual4").checked){

document.getElementById("cbParamVirtual3").disabled = false;

}else {document.getElementById("cbParamVirtual3").disabled = true;}

}

function r_boxcheck()

{

if(document.getElementById("cbParamVirtual6").checked){

document.getElementById("cbParamVirtual5").disabled = false;

}else {document.getElementById("cbParamVirtual5").disabled = true;}

}

function transfer()

{

if(document.getElementById("cbParamVirtual2").checked)

{

document.getElementById("InsertRecordCategory_ID").value = document.getElementById("cbParamVirtual1").value;

}

if(document.getElementById("cbParamVirtual4").checked)

{

document.getElementById("InsertRecordSub_Cat_ID").value = document.getElementById("cbParamVirtual3").value;

}

if(document.getElementById("cbParamVirtual6").checked)

{

document.getElementById("InsertRecordDiv_Cat_ID").value = document.getElementById("cbParamVirtual5").value;

}

}

window.onload = d_text;
document.getElementById("cbParamVirtual2").onclick = f_boxcheck;
document.getElementById("cbParamVirtual4").onclick = s_boxcheck;
document.getElementById("cbParamVirtual6").onclick = r_boxcheck;
document.getElementById("caspioform").onsubmit = transfer;
</script>

I can't seem to get this to work. Can anyone assist me?

Thank you in advance for the help.

Screenshot 2024-06-05 at 4.52.27 AM.png

Link to comment
Share on other sites

Hello @wbuchanan,

The solution depends on the use case. If you need to add newly added values to the lookup table, Virtual fields are not the right choice.

Virtual fields don`t submit data into the table. This is why a separate Submission form is used in this tech tip:

https://howto.caspio.com/tech-tips-and-articles/automatically-add-options-to-dropdowns-and-listboxes/

1) So, if it is fine to add a value to the dropdown from the virtual field without adding this value to the Lookup table, this can be resolved in a rather easy way.

2) If the value should be added to the Lookup table, this is rather complex solution. It requires adding 3 Submission forms as iFrames and JavaScript code to get the submitted value to the dropdown as a new option. 

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
Reply to this topic...

×   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...
×
×
  • Create New...