Possible Duplicate:
Submit form without page reloading
Hi I need to submit a form without reloading, how can I do this with javascript or frames?
Thanks
Possible Duplicate:
Submit form without page reloading
Hi I need to submit a form without reloading, how can I do this with javascript or frames?
Thanks
You can do this using jQuery: http://jquery.com/
Its a javascript framework and one of the methods you can use to do this kind of thing is:
$('#formID').submit(function(){
var ajaxURL = '/ajax/saveAccountSettings.php';
$.ajax({
type: 'POST',
url: ajaxURL,
data: {
username: $('#accountForm #username').val()
},
success: function(data){
//Do something
}
});
return false;
});
Probably worth reading up how to use jquery first though...
I'd recommend JavaScript over trying to do anything with iframes. What you are looking for is XHRRequest, Simplest solution would be to use JQuery. I was going write up a quick example, but this tutorial seems to cover the steps pretty good.
You could use jQuery and the jQuery Form Plugin.
jQuery Form Plugin's ajaxForm
function enables you to "hijack" a form in your HTML. Consider this example:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>
</head>
<body>
<form id="myForm" action="comment.php" method="post">
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" value="Submit Comment" />
</form>
</body>
</html>
See the plugin's website for more info. It supports various callback functions for error handling etc.