I have a form there are 5 fields where I want to automatic generate roll number in 5th field after filling up 4 fields(Name,Phone,Course,Batch) without submitting form.but after filling up 4 field no value comes in 5th field(roll).Below is my code
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <head>
<title>Untitled Document</title>
<script>
function my_validate_func() {
if ($('#name').val() != "" && $('#phone').val() != "" &&
$('#course').val() != "" && $('#center').val() != "") {
$.ajax({
type: "POST",
url: 'submit.php',
success: function(response) {
$('#roll').val(response.roll);
}
});
}
}
</script>
</head>
<body>
<form method="post" action="">
<input type="text" name="name" id="name" onchange="my_validate_func()">
<input type="text" name="phone" id="phone" onchange="my_validate_func()">
<input type="text" name="course" id="course" onchange="my_validate_func()">
<input type="text" name="center" id="center" onchange="my_validate_func()">
<input type="text" name="roll" id="roll" value="<?php $roll; ?>">
</form>
</body>
</html>
**submit.php code is below**
<?php
$roll=rand(100000,999999);
echo $roll;
?>