Dependent Select Option With MySQLi Using jQuery PHP Script


Dependent Select Option With MySQLi Using jQuery PHP Script

The Dependent select option was build using jQuery / PHP. This simple source code will show you how to create a dependent select option driven by MySQLi database server. The select option is automatically generate whenever the user choose from the first selection. It retrieve the data within the database to display the result based on the selected value.

This is the sample code

 

<!DOCTYPE html>
<?php
$conn = new mysqli('localhost', 'root', '', 'db_animal') or die(mysqli_error());
?>
<html lang = "eng">
<head>
<meta charset = "UTF-8" />
<link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css" />
</head>
<body>
<nav class = "navbar navbar-default">
<div class = "container-fluid">
<a class = "navbar-brand" href = "<a href="https://www.sourcecodester.com">Sourcecodester</a>
" rel="nofollow">https://www.sourcecodester.com">Sourcecodester</a>
</a> </div>
</nav>
<div class = "container-fluid">
<div class = "row">
<div class = "col-md-3"></div>
<div class = "col-md-6 well">
<h4 class = "text-primary">Dependent Select Option With MySQLi Using PHP / jQuery</h4>
<hr style = "border-top: 1px dotted #8c8b8b;"/>
<form class = "form-inline">
<div class = "form-group">
<label>Animal Group:</label>
<select id = "group" class = "form-control" name = "animal-groupl" required = "required">
<option value = "">Select a group</option>
<?php
$g_animal = $conn->prepare("SELECT * FROM `animal` GROUP BY `animal_group`");
if($g_animal->execute()){
$g_result = $g_animal->get_result();
}
while($f_ganimal = $g_result->fetch_array()){
?>
<option value = "<?php echo $f_ganimal['animal_group']?>"><?php echo $f_ganimal['animal_group']?></option>
<?php
}
$conn->close();
?>
</select>
</div>
<div class = "form-group">
<label>Animal:</label>
<select id = "animal" name = "animal" class = "form-control" disabled = "disabled" required = "required">
<option value = "">Select an animal</option>
</select>
</div>
</form>
</div>
</div>
</div>
</body>
<script src = "js/jquery-3.1.1.js"></script>
<script type = "text/javascript">
$(document).ready(function(){
$('#group').on('change', function(){
if($('#group').val() == ""){
$('#animal').empty();
$('<option value = "">Select an animal</option>').appendTo('#animal');
$('#animal').attr('disabled', 'disabled');
}else{
$('#animal').removeAttr('disabled', 'disabled');
$('#animal').load('animal_get.php?animal_group=' + $('#group').val());
}
});
});
</script>
</html>

I hope the source code can help you to your projects and future projects. For more update and tutorial, just kindly visit this site. Enjoy coding!!

 

 

Learn How to install Dependent Select Option With MySQLi Using jQuery PHP Script?



Find More related Dependent Select Option With MySQLi Using jQuery PHP Script



Dependent PHP Script | Select PHP Script | Option PHP Script | Wh PHP Script | Mysqli PHP Script | Using PHP Script | Jquery PHP Script | Php PHP Script | Script PHP Script | The PHP Script | Dependent PHP Script | Select PHP Script | option PHP Script | Was PHP Script | Build PHP Script | Using PHP Script | Jquery PHP Script | Php PHP Script | Th PHP Script | Simple PHP Script | Source PHP Script | Code PHP Script | Will PHP Script | Show PHP Script | How PHP Script | To PHP Script | Create PHP Script | A PHP Script | Dependent PHP Script | 2021 Top 100 Dependent PHP Script | Top 10 Select PHP Script | Top 50 Option PHP Script | 2021 Top 40 Wh PHP Script | Top 100 Mysqli PHP Script | Top 50 Using PHP Script | 2021 Top 100 Jquery PHP Script | Top 20 Php PHP Script | Top 100 Script PHP Script | Top 10 The PHP Script | Top 100 Dependent PHP Script | Top 200 Select PHP Script | Top 500 option PHP Script | Top 1000 Was PHP Script | Top 5000 Build PHP Script | Top 50 Using PHP Script | Top 50 Jquery PHP Script | Top 50 Php PHP Script | Top 50 Th PHP Script | Top 50 Simple PHP Script | 2021 Top 50 Source PHP Script | Top 50 Code PHP Script | Top 50 Will PHP Script | Top 50 Show PHP Script | Top 20 How PHP Script | Top 20 To PHP Script | Top 20 Create PHP Script | Top 10 A PHP Script | Top 10 Dependent PHP Script | Popular 100 Dependent PHP Script | Popular 10 Select PHP Script | Popular 50 Option PHP Script | Popular 40 Wh PHP Script | Popular 100 Mysqli PHP Script | Popular 50 Using PHP Script | Popular 100 Jquery PHP Script | Popular 20 Php PHP Script | Best 100 Script PHP Script | Best 10 The PHP Script | Best 100 Dependent PHP Script | Best 200 Select PHP Script | Best 500 option PHP Script | Best 1000 Was PHP Script | Best 5000 Build PHP Script | Popular 50 Using PHP Script | 2021 New 50 Jquery PHP Script | 2021 New 500 Php PHP Script | 2021 New 1000 Th PHP Script | 2021 Top 500 Simple PHP Script | 2021 Best 500 Source PHP Script | 2021 New 10 Code PHP Script | 2021 Popular 500 Will PHP Script | 2021 Popular 20 Show PHP Script | 2021 Top 200 How PHP Script | 2021 Top 4000 To PHP Script | 2021 New 20 Create PHP Script | 2021 Best 100 A PHP Script | 2021 Best 120 Dependent PHP Script |

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
InterServer Web Hosting and VPS
Horje

Horje