Jump to content

how to reference Calculated Virtual Field Value in Javascript


Recommended Posts

Please bear with me as i try to unfold this.

I have a submission datapage with a Virtual Field  (Virtual23) where as a Calculated Field i'm using a SELECT statement to fetch what I need correctly.  This is successful.

Where i'm struggling is how to reference this value in javascript.   I'm trying to store the value in a varable ...

I've tried this: 

var  x = document.getElementById("cbParamVirtual23").value;

and it doesn't seem to work.  I'm assuming the value fetched by the SELECT statement should return a string.

I've tried the below code to test if it works, but it fails. 

document.getElementById("ElderbergHTMLBlock1").innerHTML = x;
document.getElementById("ElderbergHTMLBlock1").innerHTML = x.toString();
 

 

Link to comment
Share on other sites

Solution Involves 2 Parts:

Part 1:  You need to use setTimeout() method to delay the code such that it runs AFTER the calculated fields get computed.  See https://www.w3schools.com/jsref/met_win_settimeout.asp 

 

Part 2:  You need to reference calculated fields using the document.getElementsByName with index 0  instead of by ID, this is because caspio adds some alphanumeric codes after the Virtual Parameters ID when its set to a Calculated Field.

See Code:
var x = document.getElementsByName("cbParamVirtual27")[0].value;
document.getElementById("ElderbergHTMLBlock1").innerHTML = x;

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...
 Share

×
×
  • Create New...