Joined connected dropdown :works only once but 2nd time selection nothing happen

Discussion in 'jQuery' started by vikaspa, Oct 12, 2012.

  1. #1
    html code

    <tr>
    <td bgcolor="#F0F7F1" class="vardana12black">Subject</td>
    <td colspan="2" class="subject" ><div id="subjecttd"><select name="subjectid" is="subjectid" onchange="$('#chapterdiv').load('chapterload.php?id='+this.value);">
    <?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>
    </div></td>
    </tr>
    <tr>
    <td bgcolor="#F0F7F1" class="vardana12black" >Chapter</td>
    <td colspan="2" class="bggrey" ><div align="left" id="chapterdiv"> </div></td>
    </tr>



    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>


    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 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
     
    vikaspa, Oct 12, 2012 IP