This can only be done using a custom template. Assuming you have some coding skills, you’d need to add your onclick attribute to the element just before it is shown on the page. For example:
<?php while ( $this->have_fields() ) : $this->the_field(); ?>
<?php if ( $this->field->name === 'agree' ) {
$this->field->attributes['onclick'] = 'alert("clicked!!")';
} ?>
The name of field i want to have onclick attribute is event, and values of this checkbox is tak and nie (yes and no in polish). And I paste code to the pdb-singup-custom php file, after the
<?php while ( $this->have_fields() ) : $this->the_field(); ?> and it looks like that
<?php if ( $this->field->event === 'tak' ) {
$this->field->attributes['onclick'] = 'alert("clicked!!")';
} ?>
And I still don’t see the onclick attribute at the chrome inspect element.
Did I make something wrong, at the php code or this attribute is just unseeable at chrome inspect element?
You need to check the name of the field like this:
$this->field->name === 'event'
if you need to check the value also, you can check that with:
$this->field->name === 'event' && $this->field->value === 'tak'