SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit a form without page refresh

    Hello,

    Im not sure where to post this as it has little bit of everything in it, either case I'll start here.

    I found a jquery script which submits a form without refreshing the page. Everything works but my question is how do I clear the fields from the calling page after submit the information.
    and I like to clear the page only if the correct information is entered example email format is checked.


    HTML Code:
    <form action="submit.php"  method="post">
    Name: <input name="name" id="name" type="text" /><br />
    Email: <input name="email" id="email" type="text" /><br />
    Phone Number: <input name="phone" id="phone" type="text" /><br />
    <input type="button" id="searchForm" onclick="SubmitForm();" value="Send" />
    </form>
    Code:
    <script>
    function SubmitForm() {
    var name = $("#name").val();
    var email = $("#email").val();
    var phone = $("#phone").val();
    $.post("submit.php", { name: name, email: email, phone: phone },
       function(data) {
         alert("Data Loaded: " + data);
       });
    }
    </script>

    PHP Code:
    <?php
      
    echo $_POST['name']."<br />";
      echo 
    $_POST['email']."<br />";
      echo 
    $_POST['phone']."<br />";
      echo 
    "All Data Submitted Sucessfully!"
    ?>

  2. #2
    SitePoint Addict
    Join Date
    Sep 2005
    Posts
    267
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Maybe something like this?

    Code:
    <script>
    function SubmitForm() {
    var name = $("#name").val();
    var email = $("#email").val();
    var phone = $("#phone").val();
    $.post("submit.php", { name: name, email: email, phone: phone },
       function(data) {
         $("#name").val("");
         $("#email").val("");
         $("#phone").val("");
         alert("Data Loaded: " + data);
       });
    }
    </script>

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for you help. greatly appreciated.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •