Jump to content

Use Javascript to set value of radio button field with onchange for field


Recommended Posts

Hello,

I have a field that normally would be a cascading radio button whose value is dependent on the selection of another field's dropdown value (the parent). However, I need the user to be able to over-ride the cascaded value occasionally. You can't do this normally so I'm trying to use js to do it. 

There is a  text field set to Dropdown, called 'SalesCode.'

A Virtual field (Virtual 18) is set to Cascading Text Field so it can receive a value when 'SalesCode' (the parent) is updated. 

The text field called 'Taxable' is the one I need to update. It's set to a Radio Button with 2 custom choices ('tax' or 'non'). 

The code I think I need is 'on change' for the SalesCode drop down field. Meaning when the user updates the SalesCode value, it updates Virtual18 (cascaded) and then the code takes the value of Virtual18 and puts in in the Taxable field's Radio Button value (the value in Virtual18 will always be either 'tax' or 'non' so it corresponds with the custom choices in Taxable). If the user wants to override that Taxable value they can change the radio button choice. 

The code below is something like I think I need but I can't get it to work, any help would be really great! 

<script>

$("#InsertRecordSalesCode").change(function(){

var v_tax = document.getElementsByName("cbParamVirtual18")[0].value;

document.getElementsByName("InsertRecordTaxable")[0].value = v_tax;

});

</script>

 

Link to post
Share on other sites

I figured out the solution, if anyone needs it. An EventListener makes it work: 

<script type="text/javascript">

document.addEventListener('DataPageReady', function (event) {
 
  var x = document.querySelector('[name*=cbParamVirtual18]');
 
  x.onchange = function() {

var v_virtc = document.getElementsByName("cbParamVirtual18")[0].value;

document.getElementsByName("InsertRecordTaxable")[0].value = v_virtc;

}
});

</script>

 

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