Reputation: 3
I am trying to clear my input fields after the user clicks on submit with MailChimp, although I seem to be having problems with it.
I have tried a lot of options to make it work and nothing does the trick. Can you help me?
Thanks, in advance.
HTML
<div class="mc-field-group">
<div class="row">
<div class="col-sm-6 col-md-6">
<input type="text" placeholder="Type your name here..."
value=""
name="NOME" class="form-control input-box required pull-
right" id="mce-NOME">
</div>
<div class="col-sm-6 col-md-6">
<input type="text" placeholder="Type your email here..."
value="" name="EMAIL" class="form-control input-box
required pull-left" id="mce-EMAIL">
</div>
</div>
</div>
<div class="mc-field-group">
<div class="row">
<div class="col-sm-12">
<textarea limit="1000" placeholder="Type your message here..."
style="height: 100px; width: 500px;" value=""
name="MENSAGEM" class="form-control textarea-box required"
id="mce-MENSAGEM">
</textarea>
</div>
</div>
</div>
JS
$('#mc-embedded-subscribe-form').ajaxChimp({
callback: mailchimpCallback,
url: ""
});
function mailchimpCallback(resp) {
if (resp.result === 'success') {
$('.subscription-success').html('<span class="icon_check_alt2"></span>' + ' Agradecemos por sua mensagem.<br />Entraremos em contato em breve.').fadeIn(1000);
$('.subscription-error').fadeOut(500);
} else if(resp.result === 'error') {
$('.subscription-error').html('<span class="icon_close_alt2"></span>' + 'Oops... Houve um erro ao tentar enviar sua mensagem.<br/>Por favor, tente novamente em alguns minutos.').fadeIn(1000);
}
}
Upvotes: 0
Views: 2576
Reputation: 18975
You can use $(':input').val('');
and $('textarea').val('');
$("#reset").click(function(){
$(':input').val('');
$('textarea').val('');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mc-field-group">
<div class="row">
<div class="col-sm-6 col-md-6">
<input type="text" placeholder="Type your name here..."
value=""
name="NOME" class="form-control input-box required pull-
right" id="mce-NOME">
</div>
<div class="col-sm-6 col-md-6">
<input type="text" placeholder="Type your email here..."
value="" name="EMAIL" class="form-control input-box
required pull-left" id="mce-EMAIL">
</div>
</div>
</div>
<div class="mc-field-group">
<div class="row">
<div class="col-sm-12">
<textarea limit="1000" placeholder="Type your message here..."
style="height: 100px; width: 500px;" value=""
name="MENSAGEM" class="form-control textarea-box required"
id="mce-MENSAGEM">
</textarea>
</div>
</div>
</div>
<input type="button" id="reset" value="Reset">
Upvotes: 0
Reputation: 73211
You can simply put it in your success handler, something like
$('.mc-field-group input, .mc-field-group textarea').val('')
should do the trick.
If you have the fields in a form, you can use reset on the form
$('#formId')[0].reset();
Upvotes: 0