How To Prevent From Page Refresh On Submit Button Click
i have form with one input and one submit button.
Solution 2:
Without ajax you can simply add the checked attribute in PHP. So for example if your radio group has the name radio
and one has value a
, the other b
:
<?php$a_checked = $_POST['radio'] === 'a';
$b_checked = $_POST['radio'] === 'b';
?><inputtype="radio"name="radio"value="a"<?=($a_checked ? ' checked' : '')?>></input><inputtype="radio"name="radio"value="b"<?=($b_checked ? ' checked' : '')?>></input>
So when a user submits the form and you display it again, it will be like the user submitted it even the page refreshes.
Solution 3:
<inputtype="radio"name="rbutton"id="r1">R1
<inputtype="radio"name="rbutton"id="r2">R2
<inputtype="button"id="go"value="SUBMIT" /><divid="result"></div><scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scripttype="text/javascript">
$(document).ready(function(){
$('#go').click(function(){
var val1 = $('input:radio[name=rbutton]:checked').val();
var datastring = "partialName="+val1;
$.ajax({
url: "search.php",
type: "POST",
data: datastring,
success: function(data)
{
$("#result").html(data);
}
});
});
});
</script>
Post a Comment for "How To Prevent From Page Refresh On Submit Button Click"