DesiLogi Posted June 26, 2021 Report Share Posted June 26, 2021 Hello, In a Submission form I've got js running on a Virtual field dropdown, OnChange, that updates a Text Area field (using a formula). The user may use this Virtual dropdown and update the Text Area, type some more data into it, and then change their mind and choose another option from the Virtual field drop down, which would run the onChange code again. I need is to put up a warning message with Cancel to let the user know the data already in the Text Area field will be overwritten if they choose OK. The issue is I don't want the message to show if the Text Area is blank (like when the form is first opened) because there's no data to be overwritten and the warning would be an annoyance. So the code needs to, when the Virtual Dropdown is changes, check to see if the Text Area field has any data or not. But I can't seem to reference the Text Area field's value after it's been updated by the js. Basically, the js needs to check to see if there's a value in the Text Area and, if so, run the warning. If there's no value then just run the formula. <script> $("[name='cbParamVirtual20']").change(function(){ var v_spec= document.getElementById("InsertRecordExtraDescriptionSpec").value; if(v_spec != "") { var retVal = confirm("Any data in the Specs box will be overwritten. Do you want to change templates?"); if (retVal == true) { f_copy_print_address('cbParamVirtual20', 'cke_InsertRecordExtraDescriptionSpec'); return true; } else { return false; } } if(v_spec == "") { f_copy_print_address('cbParamVirtual21', 'cke_InsertRecordExtraDescriptionSpec'); } }); </script> It seems like the line var v_spec= document.getElementById("InsertRecordExtraDescriptionSpec").value; isn't getting the current value if the user has already run this function. Any ideas on how this could be fixed? Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted June 28, 2021 Report Share Posted June 28, 2021 what's this function f_copy_print_address? Seems to run fine on my end, though, gives warning when there's data in text area, doesn't give warning when there's not, so, it's probably something in that function. Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted June 28, 2021 Author Report Share Posted June 28, 2021 Hmmn, that's odd--I'll have to test it without the function. Basically, f_copy_print_address is used to copy the value of the Virtual drop down into the Text Area box. It's something Caspio set up several years ago for me to copy Text64000 values (addresses, at the time) that I've used for other Text Area copying. Not sure why it would hang the whole thing up but I'll do some tests to see, and perhaps there's a better way to copy the value to the Text Area. Thanks for pointing that out. EDIT: On testing it seems like the issue is that, for the warning message to run, you have to manually type something into the box. If the formula runs and pastes in some data via js then it doesn't 'register' the next time the onChange runs so v_spec won't be != "" and therefore no warning message. Last edit: the code below is what I ended up using and it works well, even though the js pasted data isn't registered a v_spec. This is because in this particular use I only need the warning to show if the user has actually typed something in. If the user just switches templates (values in the Virtual dropdown) it doesn't matter if what's there is overwritten, so there's no need for a warning message in those cases. Here's the code, if anyone else needs this and thanks, TellMeWhy, for taking a look. <script> $("[name='cbParamVirtual20']").change(function(){ var v_spec= document.getElementById("InsertRecordExtraDescriptionSpec").value; if(v_spec != "") { var retVal = confirm("Any data in the Specs box will be overwritten. Do you want to change templates?"); if (retVal == true) { f_copy_print_address('cbParamVirtual20', 'cke_InsertRecordExtraDescriptionSpec'); return true; } else { return false; } } if(v_spec == "") { f_copy_print_address('cbParamVirtual20', 'cke_InsertRecordExtraDescriptionSpec'); } }); </script> 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.