Bobby5193
Bobby5193

Reputation: 1625

Jquery validate multiple inputs with email

I have a form where i ask the user to input email addresses for an automated email to be sent. I have set both the email inputs to be required and to check for valid email, but it seems to work only for the first one. What am I doing wrong here?

 <form class="validate" method="post" id="formLoc">
        <div data-role="fieldcontain">
            <label for="email-from">from</label>
            <input type="text"   class="required email" id="email-from" placeholder="from" />
        </div>
        <div data-role="fieldcontain">
            <label for="email-to">to</label>
            <input type="text" id="email-to" class="required email"  placeholder="to" />
        </div>
        <div data-role="fieldcontain">
            <label for="email-message">message</label>
            <textarea id="email-message" cols="100" rows="40"></textarea>
        </div>
        <div class="email-sent">
            <h4></h4>
        </div>

        <div class="SendEmailButton">
            <button type="submit" data-role="button" data-icon="forward" data-inline="true"
                data-mini="true" data-theme="c">send</button>
        </div>

    </form>

Here's a fiddle with the problem : http://jsfiddle.net/bobby5193/8dHg9/544/

Upvotes: 4

Views: 1025

Answers (2)

Vikas Kumar
Vikas Kumar

Reputation: 41

If you want get more than one text box to insert Email like

<ul>
  <li>
    <input id="emailcheck" type="text" placeholder="Email" name="ToEmails[0]" required />
    <input id="emailcheck" type="text" placeholder="Email" name="ToEmails[1]" required />
    <input id="emailcheck" type="text" placeholder="Email" name="ToEmails[2]" required />
  </li>
</ul>

Now we will get all email address from text box.

var email = $('input[name^=ToEmails]');  
console.log(email);

Upvotes: 0

Brian
Brian

Reputation: 1184

Add the name attribute to both input fields.

<input type="text" name="email-from" class="required email" id="email-from" placeholder="from" />
<input type="text" name="email-to" id="email-to" class="required email" placeholder="to" />
<textarea name="email-message" id="email-message" cols="100" rows="40" class="required"></textarea>

Here is a jsFiddle

Update

Here is an updated jsFiddle which has validation on the textarea. I added the name attribute and class="required" to it.

Upvotes: 2

Related Questions