1

I have this registration form. How can I send the input information to the action.php without redirecting the user to it and after that redirecting it back to this page. I want the form to be submitted in the background.

<p id="message"></p>
<form action='action.php' method='post'>
Username: <input type='text' name='username'>
Password: <input type='password' name='password'>
e-mail: <input type='text' name='email'></div>
<input type='submit' value='Register' onclick='Submit()' />
</form>
<script>
function Submit(){
document.getElementById("message").innerHTML = "You have been successfully registered";
}
</script>

Thanks!

nikitz
  • 843
  • 1
  • 10
  • 29

1 Answers1

5

http://api.jquery.com/jquery.post/ Should help you with this, here's an example that should work with the code you posted.

var data = $('form').serialize();
$.post( "action.php", data, function() {
    $('#message').text('You have been successfully registered');
})
Selven
  • 477
  • 4
  • 12