jquery add/delete valid email address
I am trying validate an email address and add that to a multi select box. For validating the email address i am using this example from jquery site. How can add i valid email address to the select box.?
开发者_如何学Go$("#myform").validate({
rules: {
field: {
required: true,
email: true
}
} })
<SELECT id="emailRecipients" multiple size=12 name=emailRecipients>
<OPTION value=avendor@gmail.com>avendor@gmail.com</OPTION>
<OPTION value=janedoe@yahoo.com>janedoe@yahoo.com</OPTION>
</SELECT>
<INPUT class="secbtn" value="Add" type="button" id="addButton">
First obtain the validated email, then:
$('#addButton').click(function(){
$('#emailRecipients').append('<OPTION value=' + email + '>' + email + '</OPTION>');
});
This will append the new option with the new email to the select once the add button is clicked.
After you have checked if the email is valid. You can
var options = $('#emailRecipients').attr('options');
options[options.length] = new Option(emailAdd, emailAdd, true, true);
Where emailAdd
is the validated email address
精彩评论