Jump to content

Statements refuse to execute in JS.....?


Recommended Posts

12 minutes ago, CoopperBackpack said:

Hello @sfraden,

Please try this code:


<script>

if(document.getElementById("cbParamVirtual11").value  == "" ) {
window.location.href = 'your URL';
}

</script>

If it doesn`t work, please specify the DataPage type  and the what are trying to achieve. 

This did not work either, which when I look at it seems to be exactly the same as I already had.  This is a report datapage.  What I am trying to do is check for the existance of a record in a totally different table.  I am using a sql query to get a specific value from that record and put it in Virtual11.  If the record exists, I get a value, if not the value is blank.  The user has clicked on a button that triggers this check to be done.  The idea is IF the Virtual11 field is blank, then load a specific page, tho if the field has something in it then ELSE show an alert message.

I have the button setup correctly and it triggers the function just fine, problem seems to be that when I put any sort of IF statement inside the function, it simply does not execute the IF/ELSE at all.  But If my function simply contains anything else BUT AN if statement, it executes perfectly fine.

 

Link to post
Share on other sites

OK, slight update, I think I have narrowed down the actual issue here, might be a bug.

When making a Virtual Field, I can access its value by using document.getElementById("cbParamVirtual12").value   I have done this many times in other places and it works perfectly.

UNLESS I make that virtual field a Calculated Value, then every attempt to access it in the same way fails as it returns NULL no matter what calulation I have going into it.... The failure renders the entire JS Script void and thats why it appears to refuse to run, due to Caspio being unable to access and return the value of a virtual calculated field

Am I doing something wrong?

Link to post
Share on other sites

Hello @sfraden,

As I understood from you reply and screenshot, you are referring to the Details DataPage.

In this case Virtual field that is set to the Calculated value has the following view:

 gCUQWM8.png

Please note that the so-called unique suffix is added to the field id (highlighted on the screenshot). This suffix is dynamic. You may find some information about it in this article https://howto.caspio.com/datapages/ajax-loading/

To get the value from the input please use the selector like this:  document.querySelector('input[id^="cbParamVirtual11"]')

Hope this helps. 

Link to post
Share on other sites
3 hours ago, CoopperBackpack said:

Hello @sfraden,

As I understood from you reply and screenshot, you are referring to the Details DataPage.

In this case Virtual field that is set to the Calculated value has the following view:

 gCUQWM8.png

Please note that the so-called unique suffix is added to the field id (highlighted on the screenshot). This suffix is dynamic. You may find some information about it in this article https://howto.caspio.com/datapages/ajax-loading/

To get the value from the input please use the selector like this:  document.querySelector('input[id^="cbParamVirtual11"]')

Hope this helps. 

Just to add, there might be conflicts if you use id^="cbParamVirtual1" as it can get Virtual 10-19, as well, you may try  document.querySelector('input[name="cbParamVirtual11"]'), so, it will be exact.

Link to post
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...