resolved
html code
<select name="subjectid" is="subjectid" >
<option value="">Select Subject</option>
<?php $query= sprintf("SELECT * FROM subject where status=1 order by srno");
echo $query;
mysql_select_db($database_DBconnect, $DBconnect);
$Result = mysql_query($query, $DBconnect) or die(mysql_error());
$rows = mysql_fetch_assoc($Result);
$totalrows=mysql_num_rows($Result);
$i=0;
?>
<?php
do {
$i++;
echo $i."<br>";
?>
<option value="<?php echo $rows['id'];?>"><?php echo $rows['name'];?></option>
<?php } while ( $rows = mysql_fetch_assoc($Result));
?>
</select>
php code
<?php
$id=$_REQUEST['id'];
$query= sprintf("SELECT * FROM subject WHERE id=%d",$id);
mysql_select_db($database_DBconnect, $DBconnect);
$Result = mysql_query($query, $DBconnect) or die(mysql_error());
$rows = mysql_fetch_assoc($Result);
$totalrows=mysql_num_rows($Result);
$i=0;
//echo "Select No. of chapters: ".$rows['name'];
?>
<select name="chapterid" id="chapterid">
<option value="">Select Chapter for <?php echo $rows['name'];?> </option>
<?php
do {
$i++;
?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php } while ( $i < $rows['chapters']);?>
</select>
JQUERY
<script type="text/javascript" language="JavaScript1.2" src="javascript/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#msgbody").hide();
$('select[name="subjectid"]').change(function () {
alert("AA");
var sval=$("#subjectid").val();
var osel=$('#subjectid').find('option:selected').text();
var prog="chapterload.php?id="+sval;
// $('#chapterdiv').empty();
$('#chapterdiv').load(prog);
});
});
</script>
when i select subject (for 1st time)
This code generates a dropdown combo box correctly.
No issues
My Problem
However when I select another value from dropdown box nothing happens
the change event is not triggered
hence the dropdown box or combo box is not populated again as per number of chapters
My Database Table
TABLE IF NOT EXISTS `subject` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` tinyint(1) DEFAULT '0',
`srno` tinyint(1) DEFAULT '0',
`briefname` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`detail` text,
`chapters` int(13) DEFAULT NULL,
`image1` varchar(255) DEFAULT NULL,
`upddt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
--
-- Dumping data for table `subject`
--
INSERT INTO `subject` (`id`, `status`, `srno`, `briefname`, `name`, `detail`, `chapters`, `image1`, `upddt`) VALUES
(14, 1, 10, 'ALG', 'Algebra', NULL, 10, NULL, '2012-03-06 15:11:11'),
(20, 1, 43, 'ENG', 'English', NULL, 11, NULL, '2012-09-28 08:04:37'),
(19, 1, 42, 'ECO', 'Economics', NULL, 5, NULL, '2012-09-28 06:19:18'),
(18, 1, 41, 'HIS', 'History', NULL, 7, NULL, '2012-09-28 04:14:58');
With this let me repeat what happens
when program starts
and I Select Subject English
the another dropdown box appears with following values
( there are 1 to 11 values because there are 11 chapters in English)
values in 2nd dropdown:
Select Chapter for English
1
2
3
4
5
6
7
8
9
10
11
which is correct
however if i select Economics
Nothing happens
I expect the drop-down box to appear with values 1 to 5
but the drop-down box for chapters are not populated again for values 1 to 5 for Economics
Surprisingly this works Ok if i use
$("#chapterdiv").append("text " );
instead of
$('#chapterdiv').load(prog);
Definitely i am not getting the result but change event displayed / appends the word "text"