Alex Stelea
Alex Stelea

Reputation: 1219

Getting the value of an input element in Jade

Is it possible to access the input value of an element using JADE? I am trying to achieve something similar to document.getElementById('aDiv').value in JS.

The code I have is the following:

extends ../layout

block content
  form.form-horizontal(id='signup-form', method='POST')
    input(type='hidden', name='_csrf', value=token)
    legend Become a bee!

    .form-group
      label.col-sm-3.control-label(for='age') Age
      .col-sm-7
        input.form-control(type='age', name='age', id='age', placeholder='Enter your age', autofocus)
    .form-group
      label.col-sm-3.control-label(for='parent-email') Parent's Email
      .col-sm-7
        input.form-control(type='text', name='parent-email', id='parent-email', placeholder='Parent Email')
    .form-group
      .col-sm-offset-3.col-sm-7
        button.btn.btn-success(type='submit')
          i.fa.fa-check
          | Signup

I want to be able to read the age field, and then depending on the value, load an additional input element, but I can't find any way to read the value client side in jade.

Thanks for the help.

Upvotes: 0

Views: 1522

Answers (1)

LocalPCGuy
LocalPCGuy

Reputation: 6116

The client side code will be HTML, not JADE. You can add the additional input into the JADE so it gets rendered to the page, and give it a CSS class to hide it. Then use standard JavaScript to show the input or not depending on the value in the age field.

Upvotes: 1

Related Questions