Get form input value inside function
Trying to figure out why this input value can't be extracted from this function:
- function valEmail(selname) {
- $('form.cd-form input[name^="email"]').each(function(selname) {
- if (inputck == 1) {return;}
- if (typeof selname === "undefined") {var email = $(this)}
- else {var email = $('form.cd-form input[name=selname]'); console.log('Inside Defined'); inputck = 1}
- console.log('Email: ' + email);
- console.log('Email val: ' + email.val());
- var elen = email.val().length;
- });
- }
With this html:
- <form class="cd-form otherclass">
- <fieldset>
- <div class="icon">
- <label class="cd-label" for="email-">Email</label>
- <input class="email" type="email" name="email-" required>
- </div>
- ... other inputs
- </fieldset>
- </form>
When valEmail(selname) called, I get:
Email: object Object
Email val: undefined
So why is value undefined - how do I get it? I've verified selname is "email-"
Thanks.