开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜