I am using onclick function in my template file, here is my html
<div class="input-box">
<input type="checkbox" name="change_password" id="change_password" value="1" onclick="setPasswordForm(this.checked)" title="<?php echo 'Change Password'; ?>"<?php if($_user->getChangePassword()==1): ?> checked="checked"<?php endif; ?> class="checkbox" />
</div>
Below is my javascript code
<script>
require([
'jquery',
'mage/mage'
], function($){
function setPasswordForm(arg){
if(arg){
$('current_password').up(4).show();
$('current_password').addClassName('required-entry');
$('password').addClassName('required-entry');
$('confirmation').addClassName('required-entry');
}else{
$('current_password').up(4).hide();
$('current_password').removeClassName('required-entry');
$('password').removeClassName('required-entry');
$('confirmation').removeClassName('required-entry');
}
}
<?php if($_user->getChangePassword()): ?>
setPasswordForm(true);
<?php endif; ?>
});
</script>
How to use it in magento2? It is working fine in m1.
I am getting below error when used above code
Uncaught ReferenceError: setPasswordForm is not defined