Solved

Clear form input field AJAX Success

Posted on 2016-07-30
1
75 Views
Last Modified: 2016-08-09
I would like to clear the email field of my form after the AJAX call returns success.  However, I can't seem to make it work.  Any suggestions will be appreciated:

 <script>
                                  var email = $('#email');
                        $(function () {
                            $("#newsjoin").on('submit', function (e) {
                                e.preventDefault();
                            });
                            $("#submit").click(function () {
                                $.ajax({
                                    url: 'http://MYSITE.com/includes/functions.php',
                                    data: $("#newsjoin").serialize(),
                                    method: 'get',
                                    success: function (d) {
                                        if (d.length) {
                                            // there are no errors
                                            $( "#successmessage").html(function() {
 var successmessage = d;
  return successmessage;
// CLEAR INPUT HERE???
});
                                        } 
                                    }
                                });
                            });
                        });
                    </script>
<html>
<form method="post" id="newsjoin" method="post"  on>
<input name="email" type="text" id="email" class="newsletter-input"/>
<input name="submit" type="image" id="submit" src="img/buttons/submit.png" alt="Join Mailing List" />
</form>

Open in new window

0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
Branislav Borojevic earned 500 total points
ID: 41736042
You should include this in your script:

$("#newsjoin")[0].reset();

Open in new window


or in plain javascript:

document.getElementById("newsjoin").reset();

Open in new window


That should do it.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question