Passing values from text field to a javascript function in Drupal 8 i am new to Drupal and i am building a form (Drupal 8)that needs to calculate an amount based on the input in two text fields.
What i want to achieve is for the "calculate" button to be hidden until the two text fields have been filled but i'm not sure how to achieve this with behaviors.
Code example:

    $form['weight'] = array(
        '#type'  =&gt; 'number',
        '#title' =&gt; t('Weight:'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array(
            'id' =&gt; 'weight',
            ),
    );        
    $form['number'] = array(
        '#type'  =&gt; 'number',
        '#title' =&gt; t('Number:'),
        '#required' =&gt; TRUE,
        '#attributes' =&gt; array(
            'id' =&gt; 'number',
            ),

    );  
   // Here if weight and number are not empty, show button


Thanks
You do not need to use Drupal Behaviours for this, this can be done with States API which ultimately uses javascript.

e.g.

$form['calculate'] = array(
  '#type' =&gt; 'submit',
  '#states' =&gt; array(
    // Only show this field when the 'toggle_me' checkbox is enabled.
    'visible' =&gt; array(
      ':input[name="weight"]' =&gt; array(
        'filled' =&gt; TRUE,
      ':input[name="number"]' =&gt; array(
        'filled' =&gt; TRUE,
      ),
    ),
  ),
);


You can change the fields name as per your requirement. Hope this will help.

Thanks