DesiLogi Posted March 6, 2017 Report Share Posted March 6, 2017 I'm trying to get some js to work with a Virtual field (currently set to a list box with 3 choices) when the selection changes (i.e. when the user clicks on choice 1,2,or 3 in the list of the Virtual field). I was able to get the rest of the code to work using a button but I'd like it to work directly when the user changes the selection in the listbox of the Virtual field. Here's what I've got so far. It's the onchange part I need help with: <div style="text-align: center;"> <script> $("[name='cbParamVirtual1']").change(function(){ var dtid = document.getElementsByName("cbParamVirtual1")[0].value; if (dtid == 1){ document.getElementById("InsertRecordMyField2").value = ""; document.getElementById("InsertRecordMyField3").value = ""; } else if (dtid == 2){ document.getElementById("InsertRecordMyField1").value = ""; document.getElementsByName("InsertRecordMyField3")[0].value = ""; } else if (dtid == 3){ document.getElementsByName("InsertRecordMyField1")[0].value = ""; document.getElementById("InsertRecordMyField2").value = ""; } } </script> </div> One thing also- I would prefer the Virtual field to actually be a real field (I couldn't get the var 'dtid' to work with a regular field though) that's a Radio button instead of a list- so that's the ultimate goal of this code. But just getting it to work with a Virtual field Listbox using 'change' would be a big help. Thanks- UPDATE: I am working through the process in steps on this datapage and just added virtual fields that use the MyField1,2,3 as the Parent fields for Cascading Text (on the Virtual field). This seems to disable the code above (perhaps because of the MyField1,2,3 is 'null' there can't be a cascade?). Any help with incorporating this into the code would be great as well. Quote Link to comment Share on other sites More sharing options...
MBhalli Posted April 16, 2017 Report Share Posted April 16, 2017 On 3/6/2017 at 10:04 AM, DesiLogi said: I'm trying to get some js to work with a Virtual field (currently set to a list box with 3 choices) when the selection changes (i.e. when the user clicks on choice 1,2,or 3 in the list of the Virtual field). I was able to get the rest of the code to work using a button but I'd like it to work directly when the user changes the selection in the listbox of the Virtual field. Here's what I've got so far. It's the onchange part I need help with: <div style="text-align: center;"> <script> $("[name='cbParamVirtual1']").change(function(){ var dtid = document.getElementsByName("cbParamVirtual1")[0].value; if (dtid == 1){ document.getElementById("InsertRecordMyField2").value = ""; document.getElementById("InsertRecordMyField3").value = ""; } else if (dtid == 2){ document.getElementById("InsertRecordMyField1").value = ""; document.getElementsByName("InsertRecordMyField3")[0].value = ""; } else if (dtid == 3){ document.getElementsByName("InsertRecordMyField1")[0].value = ""; document.getElementById("InsertRecordMyField2").value = ""; } } </script> </div> One thing also- I would prefer the Virtual field to actually be a real field (I couldn't get the var 'dtid' to work with a regular field though) that's a Radio button instead of a list- so that's the ultimate goal of this code. But just getting it to work with a Virtual field Listbox using 'change' would be a big help. Thanks- UPDATE: I am working through the process in steps on this datapage and just added virtual fields that use the MyField1,2,3 as the Parent fields for Cascading Text (on the Virtual field). This seems to disable the code above (perhaps because of the MyField1,2,3 is 'null' there can't be a cascade?). Any help with incorporating this into the code would be great as well. Please add ); after the last } and before </script> Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted April 20, 2017 Author Report Share Posted April 20, 2017 I'll give that a shot- didn't notice that and thanks for the suggestion. 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.