HTML Form එකක Select box එකකින් select කරන value එකක් (Form එක Submit කරන්න කලින් Onchange) javascript function එකක් හරහා MySQL Query එකකකට යවන්නෙ කොහොමද. Ajax වලින් Try කලා Success Alert එක එනවා එත් value එක PHP කෝඩ් එකට Pass වෙන්නේ නෑ. මේක වෙන්න ඕනේ එකම ෆයිල් එකක.
HTML FORM PART
JS AND AJAX PART
PHP MySQL PART
HTML FORM PART
<select name="brand" id="brand" onChange="make()" required>
JS AND AJAX PART
<script>
function make() {
var x = document.getElementById("brand").value;
$.ajax({
url: "cardetails.php",
type: "POST",
data: {x:x},
success: function(response){
alert("success");
},
error: function (xhr, ajaxOptions, thrownError) {
alert("fail");
}
});
}
</script>
PHP MySQL PART
<?php
$br =$_POST['x'];
echo $br;
$sql="select * from model where s_name = '$br' ";
?>
Last edited: