Reputation: 484
is it possible to submit this php form without refreshing the page. how would i go about setting a jquery code that can do this.
<?php
if(!isset($_POST['sthis']))
{
?>
<div id="show">
<form method="post" action="">
something<input name="sthis" type="text" id="sthis" />
<input name="s" type="submit" value="submit" id="submit" />
</form>
</div>
<?php
}
else
{
if(isset($_POST['sthis']))
$sthis = $_POST['sthis'];
if(empty($sthis)){echo 'put something in this box';}
else echo 'ready';
}
?>
Upvotes: 0
Views: 1650
Reputation: 691
This is how to use jQuery:
HTML
<form id="frmSample">
...
</form>
<div id="divResult"></div>
JQuery
$(function(){
$("#frmSample").submit(function(){
//some code here
$("#divResult").load("yourPhpCode.php", {variableName: value, variableName1: value});
});
});
Check out the documentation.
Upvotes: 1
Reputation: 100205
You will need ajax for that:
$.ajax({ type: "POST", url: "your url here", data: "sthis=someValue", success: function(response) { alert(response); } });
Hope it helps
Upvotes: 1