Jump to content

Update Field Value based on JS if statement


Recommended Posts

I want to create a JS if statement that updates a fields value based on another fields value.

If the field Virtual2 does not equal "Don't Share" I want the field CON_1 to equal Virtual2 

Here is what I used unsuccessfully in the footer of a details page in a tabular report data page...

 

<SCRIPT LANGUAGE="JavaScript">

function con1()
{
   var v2 = parseFloat(document.getElementById("InsertRecordVirtual2").value);
   if(v2="Don't Share")
{}
else
{document.getElementById("InsertRecordCON_1").value = (v2);}
}

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

</SCRIPT>

 

CON_1 is a text data type and Virtual2 is a virtual field drop down that on default = "Don't Share" 

Thanks Guys!

Any help would be greatly appreciated! :)

Link to comment
Share on other sites

This should be what you are looking for:

 

 <SCRIPT LANGUAGE="JavaScript">

function con1()
{
   var v2 = document.getElementById("InsertRecordVirtual2").value;
   if (v2 !="Don't Share")
{
document.getElementById("InsertRecordCON_1").value = v2;
}
}

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

</SCRIPT>

  

 

Link to comment
Share on other sites

Thank you for the reply!

Unfortunately the script did not update CON1's value.

Does the fact that this script is running in a details page change what should be used in the following line? 

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

Should "caspioform" be changed to something like "caspiodetailspage"

That is the only thing I can think of as to why CON_1 is not being updated.

Thanks again for the help! I really appreciate it!

Link to comment
Share on other sites

  • 2 years later...

Hi @BridgeWay,

Just an update: You can also use the Calculated Values without using JS. Calculated Value form element generates dynamic calculations that automatically update as users interact with your form. Similar to Formula Fields and Calculated Fields, you can construct the calculation using functions, logic, constants, values from other fields and SQL expressions. For more information about Calculated Values, check this article: https://howto.caspio.com/datapages/datapage-components/calculated-values/

Hope it 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
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...