php


I use change event but I when I put value to the select option on course the major does not append data..


First I have to select a course after I select options from major will append on the second select
the problem is
when i put value to the course option the major option will not append
when I remove the value the major will append
Please help me I dont know where was ther error..
$(document).ready(function() {
<?php
include'connection.php';
$sql = "select * from course";
$res=$conn->query($sql);
while ($row=$res->fetch_array())
{
$course[]=$row['course_name'];
}
?>
<?php
foreach ($course as $coursename)
{
echo "var ".$coursename." = [ ";
$sql = "Select *,course.course_name,course.course_name from major inner join course on course.course_id = major.course_id where course_name = '".$coursename."'";
$res=$conn->query($sql);
while($row=$res->fetch_array())
{
?>
{display:"<?php echo $row['major_name'];?>", value:"<?php echo $row['major_id'];?>"},
<?php
}
echo '];';
}
?>
// Function executes on change of first select option fiel
$("#course").change(function(){
var select = $("#course option:selected").val();
switch (select)
{
<?php
$sql="select * from course";
$res=$conn->query($sql);
$count=$res->num_rows;
while($row=$res->fetch_array())
{
?>
case "<?php echo $row['course_name']; ?>":
major(<?php echo $row['course_name']; ?>);
break;
<?php
}
?>
default:
$("#major").empty();
$("#major").append("<option>--Select--</option>");
break;
}
});
// Function To List out Cities in Second Select tags
function major(arr)
{
$("#major").empty(); //To reset cities
$("#major").append("<option>--Select--</option>");
$(arr).each(function(i)
{ //to list cities
$("#major").append("<option value=\"" + arr[i].value + "\">" + arr[i].display + "</option>")
});
}
function course(arr) {
$("#course").empty(); //To reset cities
$("#course").append("<option>--Select--</option>");
$(arr).each(function(i) { //to list cities
$("#course").append("<option value=\"" + arr[i].value + "\">" + arr[i].display + "</option>")
});
}
});
</script>
<label for="form_phone">10.Course</label>
<select name="course_id" id="course" class="form-control" required="">
<option>--Select--</option>
<?php
include"connection.php";
$res=$conn->query ("Select course_id,course_name from course");
$count=$res->num_rows;
if($count > 0)
{
while($row=$res->fetch_array())
{
?>
<option value="<?php echo $row['course_name']; ?>">
<?php echo $row['course_name'];?>
</option>
<?php
}
}
?>
</select>
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label for="form_phone">11.Major</label>
<select name="major" id="major" class="form-control">
<!-- dependent on course -->
</select>
</div>
</div>
When you're saying 'append' do you mean the options for the majors aren't populating the drop down based on the criteria of the course selection?
Is this a homework assignment?

Related Links

php multidimensional array group number of occurrences by type and date
Laravel 5 global date accessor
load and parse HTML string
get all data from a variable
Insert new row into table every minute with cron job
Facebook php SDK Just display Name and ID
Storing a datetime with optional parameters in an elasticsearch index?
Finding DIV's in a php | Wordpress
Cannot require parent directory in phpUnit
How to upload two files at two different paths in Yii2?
How to add “you save” option in the shopping cart of opencart?
Error 403 refreshing GMAIL token with PHP
Set Table Cell Alignment - PHPPowerPoint
doctrine:generate:crud for Entites outside a bundle
Symfony 2 lags on ubnutu and making it too slow
Strange PHP date comparison error

Categories

HOME
hpoo
elasticsearch
adfs3.0
livecode
barcode-scanner
swi-prolog
add-on
haproxy
dry
risk-management
initialization
capistrano
firebase-database
save
graphql-js
gtk
multi-step
live-streaming
sslhandshakeexception
scala-ide
scheduled-tasks
cmake-gui
bluemix-mobile-services
conda
stackexchange.redis
backendless
web-push
unordered-multimap
high-availability
xdebug
echosign
es6-modules
memory-fences
om-next
nest
db2-luw
express-session
busboy
des
keyboard-layout
redgate
stackpanel
forms-authentication
fastlane
oauth2-playground
classnotfoundexception
reverse-dns
doctrine-extensions
kitura
cyanogenmod
sharpdx
solr-query-syntax
embedded-v8
asp.net-web-api-routing
mongodb-aggregation
kendo-treeview
oid
haraka
bigdecimal
zynq
currency-exchange-rates
ioexception
linuxbrew
stack-smash
dsa
ambiguity
gluon-desktop
fuseesb
mxe
jolie
juttle
libgcc
box2dweb
bittorrent-sync
radius-protocol
boolean-algebra
django-sites
iosched
armv6
lru
microformats
flv
rikulo
cmath
icenium
border-box
pcspim
gamesalad
litespeed
grails-validation
ccl
tessellation
icicles
resharper-5.0
mysqli-multi-query
rawcontacts
iphone-sdk-3.1.3
chronic

Resources

Encrypt Message