Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Clear form input field AJAX Success

Posted on 2016-07-30
1
Medium Priority
?
134 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 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…
Suggested Courses

715 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