In this demonstration, I am building a dynamic conditional drop-down list using Java script and Ajax.
PHP: Add Data
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
//including the database connection file
include_once("config.php");
if(isset($_POST['Submit'])) {
...
HTML: Create Data
<html>
<head>
<title>Create Data</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<a href="index.php">Back to Home</a>
<br/><br/>
<form action="add.php" method="post" name="form1">
<table width="25%" border="0">
<tr>
<td>Name of the Request</td>
...
Javascript:
$(document).ready(function(){
load_json_data('type');
function load_json_data(id, parent_id)
{
var html_code = '';
$.getJSON('options.json', function(data){
...
JSON DATA:
[
...
The form submission process currently saves the IDs instead of the corresponding names into the database from the JSON data.
For example,
{
"id":"10",
"name":"bus Archive",
"parent_id":"2"
}
In the above scenario, the ID 10 gets stored in the database rather than the actual item name bus Archive.