Jump to content

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. 

Link to post
Share on other sites
  • 1 month later...
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>

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...