Jump to content
DesiLogi

use on change of Virtual field for running code

Recommended Posts

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. 

Share this post


Link to post
Share on other sites
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>

Share this post


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...