Set value of radio button element using JS

Mono

Member
I'm struggling a bit here, but had fantastic help here before so I thought I'd ask again.

I want to set the value of one set of radio buttons based on the selection in another.

Thanks
 
You probably want an onchange javascript function, something like this (place in Javascript Code section):
Code:
requirejs(['fab/fabrik'], function () {
  var fabrikBlock = Fabrik.getBlock('form_XX');
  var value = fabrikBlock.formElements.get('tablename___elementname').get('value');
  var target = fabrikBlock.formElements.get('tablename___elementname');
    if (value == 0) {
        target.setValue("y");    // where y is the option value
    }
    // etc.
});
Change the tablename__elementname to the appropriate names of your elements, and change the form_XX to the form number of your form.

I haven't tested this code but I have done very similar things in many elements.
 
Thanks for your quick reply.
I have tried with the code but I'm new to this and must have something wrong.
Could you advise me?

JavaScript:
requirejs(['fab/fabrik'], function () {
  var fabrikBlock = Fabrik.getBlock('9');
  var value = fabrikBlock.formElements.get('tbl_vehicle___powered_vehicle').get('value');
  var target = fabrikBlock.formElements.get('tbl_vehicle___needs_inspections');
    if (value == 2) {
        target.update('0'); 
    }
 
});
 
Better in javascript actions, validations should be used to decide if the entered value is correct or not.

Thanks for the update Hugh.
 
Thanks again, the help here is fantastic.
I'm trying to work towards creating a popup form to add new records.

I have 3 lists Make, Model, and Vehicle.

I have a form which has a database join for Make, a cascading dropdown for Model and a field for a Licence Plate.
in this form I am trying to add a button for New Make and New Model.

Because you two know so much more than me, maybe you could speed up my learning?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top