immexerxez immexerxez - 4 years ago 107
Javascript Question

jQuery get value from form returns Undefined

I've come across multiple answers to this question and have not found one that works. I am using pug(jade) and trying to get the value from a modal form.

here is the pug:

#myModal.modal.fade(tabindex='-1', role='dialog', aria-labelledby='myModalLabel',data-keyboard="false", data-backdrop="static")
.text-center.h4#myModalLabel.modal-title(style="color:#4c86ff; font-family: 'Lora', serif; font-size:20px; font-weight:600") please add your symptoms
form.form-horizontal(action='/token' ,id='symptoms', method='POST')
input(type='hidden', name='_csrf', value=_csrf)
input.textarea.form-control(type='text', name='symptomsInput', id='symptomsInput', placeholder='What are your symptoms?', autofocus, required)
button.btn.btn-primary#button-grabToke(type='submit' data-toggle="modal" data-target="#myModal") Go!

and here is my js:

var symptoms = $('#DynamicValueAssignedHere').find('input[name="symptomsInput"]').val();

Answer Source

i dont think i can find the problem without knowing where #DynamicValueAssignedHere is. But on thing, i think its easier on jquery to find(an id) rather than a input[name:


check your browser debugging and make sure #DynamicValueAssignedHere is a decendant of #symptomsInput. I bet its not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download