Solved

Clear form input field AJAX Success

Posted on 2016-07-30
1
51 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

861 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