RonAnderson Posted July 22 Report Share Posted July 22 Hi, I have a textbox with an associated "Confirm" textbox. If the values in both boxes don't match, I want a mechanism to immediately inform the user and not have to wait until the submit button is clicked. I've tried, using a virtual calculated value box with:- CASE WHEN CAST([@field:Barcode_ID] AS String) = CAST([@field:Barcode_ID@Confirm] AS String) THEN "Barcode is valid" ELSE "Barcode is Invalid" END I get an error after clicking "Verify Formula". The error is "Type String is not a defined system type. Invalid column name '@field:Barcode_ID@Confirm'." The entry could be alpha numeric that's why I've tried using "String". I've tried using Calculated Value but if a javascript solution with an "alert" is available then I'd prefer to use that. Your help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
RonAnderson Posted July 23 Author Report Share Posted July 23 Hi, I've turned to JS to try to solve this but it's still not giving me a result. Here's the code I'm working with:- <script type="text/javascript"> var pwd = document.getElementById('Barcode_ID'); var pwdc = document.getElementById('InsertRecordBarcode_ID@Confirm'); if(pwdc.value <> pwdc.value}{alert "Error"} </script> I've placed this code in the footer with the HTML editor disabled. If you can spot where I'm going wrong, I'd be really grateful if you could let me know. Cheers, Ron Quote Link to comment Share on other sites More sharing options...
cheonsa Posted July 23 Report Share Posted July 23 23 hours ago, RonAnderson said: Hi, I have a textbox with an associated "Confirm" textbox. If the values in both boxes don't match, I want a mechanism to immediately inform the user and not have to wait until the submit button is clicked. I've tried, using a virtual calculated value box with:- CASE WHEN CAST([@field:Barcode_ID] AS String) = CAST([@field:Barcode_ID@Confirm] AS String) THEN "Barcode is valid" ELSE "Barcode is Invalid" END I get an error after clicking "Verify Formula". The error is "Type String is not a defined system type. Invalid column name '@field:Barcode_ID@Confirm'." The entry could be alpha numeric that's why I've tried using "String". I've tried using Calculated Value but if a javascript solution with an "alert" is available then I'd prefer to use that. Your help would be greatly appreciated. Hi @RonAnderson, For this formula, you can use a Virtual field instead of a confirmation textbox. CASE WHEN [@field:Barcode_ID] = '' OR '[@cbParamVirtual1]' = '' THEN '' WHEN [@field:Barcode_ID] = '[@cbParamVirtual1]' THEN "Barcode is valid" ELSE "Barcode is Invalid" END The reason why you got an error is because of the confirmation field [@field:Barcode_ID@Confirm]. If you will check the picker button, this field is not available. Thus, you cannot use it in the formula. Quote Link to comment Share on other sites More sharing options...
cheonsa Posted July 23 Report Share Posted July 23 4 hours ago, RonAnderson said: Hi, I've turned to JS to try to solve this but it's still not giving me a result. Here's the code I'm working with:- <script type="text/javascript"> var pwd = document.getElementById('Barcode_ID'); var pwdc = document.getElementById('InsertRecordBarcode_ID@Confirm'); if(pwdc.value <> pwdc.value}{alert "Error"} </script> I've placed this code in the footer with the HTML editor disabled. If you can spot where I'm going wrong, I'd be really grateful if you could let me know. Cheers, Ron Hi @RonAnderson, Here's the JavaScript solution as well: <script type="text/javascript"> document.addEventListener('DataPageReady', onChangeFunction) function onChangeFunction() { document.getElementById("InsertRecordBarcode_ID").addEventListener('change', Alert); document.getElementById("cbParamVirtual1").addEventListener('change', Alert); document.removeEventListener('DataPageReady', onChangeFunction) } var x = document.querySelector('[id*=InsertRecordBarcode_ID]'); var y = document.querySelector('[id*=cbParamVirtual1]'); function Alert(event) { if (x.value != y.value && x.value != '' && y.value !='') alert("Barcode is Invalid"); } </script> You may paste this in the Footer of the DataPage. Hope this helps Quote Link to comment Share on other sites More sharing options...
RonAnderson Posted July 23 Author Report Share Posted July 23 Hi @cheonsa This worked for me, thank you so much. However, I actually want the alert message to show if the two values differ. I tried:- if (x.value !<> y.value && x.value !<> '' && y.value !='') but it failed. Could you help me that last step and amend the code? I'm a rookie when it comes to JS. Best regards, Ron Quote Link to comment Share on other sites More sharing options...
cheonsa Posted July 24 Report Share Posted July 24 On 7/23/2023 at 11:24 AM, RonAnderson said: Hi @cheonsa This worked for me, thank you so much. However, I actually want the alert message to show if the two values differ. I tried:- if (x.value !<> y.value && x.value !<> '' && y.value !='') but it failed. Could you help me that last step and amend the code? I'm a rookie when it comes to JS. Best regards, Ron Hi @RonAnderson, It's good to know that it works for you. Based on this condition, the alert message will prompt if the value of x and y is not equal. I just added that x and y should not be blank so it will not be displayed upon loading the DataPage. if (x.value != y.value && x.value != '' && y.value !='') May I know what is the actual result on your end? Quote Link to comment Share on other sites More sharing options...
RonAnderson Posted July 24 Author Report Share Posted July 24 Hi @cheonsa Again, thanks for your response. I did as instructed and replaced the line of code which you kindly provided. Unfortunately, I get the "Barcode is invalid" if the entries match or not. Here's the code I'm working with:- I don't know JS very well so I can't assess if I've done something wrong or accidentally skewed the code. Could you review and let me know please. Thanks again, Ron Quote Link to comment Share on other sites More sharing options...
DrSimi Posted July 26 Report Share Posted July 26 Hi @RonAnderson, Below you may find a sample code that should work with the main "Repeat for confirmation" feature and without using Virtual Fields. The alert will trigger only when the fields have mismatching data in them, and not when either or both of them are empty. <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { document.querySelector("[id='InsertRecordBarcode_ID']").addEventListener('change',ShowAlert); document.querySelector("[id='InsertRecordBarcode_ID@Confirm']").addEventListener('change',ShowAlert); function ShowAlert() { var field = document.querySelector("[id='InsertRecordBarcode_ID']").value; var confirm_field = document.querySelector("[id='InsertRecordBarcode_ID@Confirm']").value; if (field && confirm_field) { if (field != confirm_field) { alert("Text does not match") } } } }); </script> Quote Link to comment Share on other sites More sharing options...
RonAnderson Posted July 26 Author Report Share Posted July 26 Hi @DrSimi Brilliant, Thanks a million. Works perfectly. I'd never have worked the syntax through. Kind regards, Ron Quote Link to comment Share on other sites More sharing options...
Kronos Posted August 17 Report Share Posted August 17 Hi, just to add a similar forum thread just in case it might help and give a different approach to the desired output: 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.