I want a function that loads the values from a PHP form and show the result in a div in the same file ;
I have a form in PHP file with the code bellow :
<?php
echo "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>";
echo"<script type='text/javascript' src='script.js'></script>";
echo"<form method='post' action='' >";
echo " <select name='mat'><option value=''>Choose: </option>";
echo"<option >hello</option>";
echo"</select>";
echo"<input type = 'submit' value='next' onclick='submit();' />";
echo"</form>";
echo"<div id ='result'> </div>";
?>
and the function in script.js
is :
function submit() {
$(function () {
var mat = "mat";
var dataString = 'mat=' + mat;
$.ajax({
type: "POST",
url: "check.php",
data: dataString,
success: function (res) {
goToByScroll("result");
$('#result').html("<br><br><br><br><br><br><br><br><br><br>").hide().fadeIn(2500, function () {
$('#result').html(res + "<br /><br /> Finished");
});
}
});
return false;
});
}
and the check.php
that load the values is :
<?php
function safe($value)
{
htmlentities($value, ENT_QUOTES, 'utf-8');
return $value;
}
if (isset($_POST['mat'])) {
$mat = safe($_POST['mat']);
echo ($mat);
}
elseif (!isset($_POST['mat'])) {
header('Location: error?mat=notfound');
} ?>
But when I click next in the fist PHP file, it doesn't show anything, can you find the error?