Form client interactions

Fill in some numbers. There is an onblur event on the height field.

$form = new Barebone\Form();

$form->addInput('text', 'Mass (kg)', 'mass', ['class'=>'form-control']);

$heightinp = $form->addInput('text', 'Height (m)', 'height', ['class'=>'form-control']);
$heightinp->setAttribute('onblur', "
    if ($('input[name=mass]').val() > 0 && $('input[name=height]').val() > 0){
        var res = parseFloat($('input[name=mass]').val()) / Math.pow(parseFloat($('input[name=height]').val()),2);
        $('input[name=result]').val(res);
    }");
    
$form->addInput('text', 'Result', 'result', ['class'=>'form-control']);

$this->view->form = $form;

Form client interactions