Check a Checkbox with Code

[ad_1]

Hello @eberkland

Assuming you have the fieldname1, with two choices, fruits and vegetables, and the checkbox field fieldname2 with the choices bananas, strawberries, carrots, and lettuce. If the user selects fruits in fieldname1 you want to tick the bananas, strawberries choices in fieldname2, carrots, and lettuce choices if the user selects vegetables.

You can insert a calculated field in the form to be used as an auxiliary (you can hide it by ticking a checkbox in its settings), and enter the equation:


getField(fieldname2|n).setVal(IF(fieldname1=='fruits', ['bananas', 'strawberries'], ['carrots', 'lettuce']))

Or if you prefer to implement the equation with function structure:


(function()
if(fieldname1=='fruits')n).setVal(['bananas', 'strawberries']);
else n).setVal(['carrots', 'lettuce']);

)()

Best regards.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer