sfraden Posted April 13, 2021 Report Share Posted April 13, 2021 I can verify the function IS being called, but the IF statement is not executing at all. Note if I remove the IF and go straight to the URL, it works, is there some reason why the IF is non-functional? Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted April 13, 2021 Report Share Posted April 13, 2021 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. Quote Link to comment Share on other sites More sharing options...
sfraden Posted April 13, 2021 Author Report Share Posted April 13, 2021 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. Quote Link to comment Share on other sites More sharing options...
sfraden Posted April 13, 2021 Author Report Share Posted April 13, 2021 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? Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted April 14, 2021 Report Share Posted April 14, 2021 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: 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. Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted April 14, 2021 Report Share Posted April 14, 2021 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: 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.