Reputation: 4425
I've the following form which I want to post to page.php and want to get result calculted on page.php and want to show that data in the table boxes using AJAX or JQUERY, is this possible? If yes so let me know please. I don't want to refresh the page as I want to be filled all data on single page and want to display all results on that page(IN table cells as user input data in one table and it will update its response).
<form method = "post" action = "page.php">
<input type = "text" name = "fld1" id = "fld1" />
<input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled />
...
</form>
Upvotes: 2
Views: 11586
Reputation: 1423
Yes it is possible. Take a look at this example.
On your page.php
<?php
echo $_POST["fld1"];
?>
On your myForm.html. event.preventDefault() is needed, otherwise submit will perform at default and page will be reload.
<script>
$(function(){
$("#submit").click(function(event){
event.preventDefault();
$.ajax({
type:"post",
url:"page.php"
data:$("#form").serialize(),
success:function(response){
alert(response);
}
});
});
});
</script>
<form id="form" method = "post" action = "page.php">
<input type = "text" name = "fld1" id = "fld1" />
<input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled />
<input type="submit" value="Submit" id="submit">
</form>
Upvotes: 5