下拉列表未在另一个下拉列表中发布相应的值

时间:2013-09-09 05:06:02

标签: php javascript codeigniter

在下面的代码中是一个更新部分,它有2个文本框和2个下拉列表,当我选择课程代码时,它应该在主题中发布correspongind值,但它不发布任何值。任何人帮助我。

  view:subject_detail_view

<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.js" ></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.min.js" ></script>
<section id="tables">
<script>
 jQuery(document).ready(function() {
  oTable = jQuery('#studenttable').dataTable({
   "bJQueryUI": true,
   "sPaginationType": "full_numbers"

  });
   }); 
  </script> 
  <script type="text/javascript" charset="utf-8">
 function get_studentdetails() {

    var exam_name = jQuery('#exam_name_id').val();
    //alert("exam_name"+exam_name);
    jQuery.ajax({
        data: {
            exam_name: exam_name,
        },
        type: 'POST',
        url: 'student_site/studentupdate',          
        success: function(data){
        //alert("inside change");
            console.log(data);
            jQuery('#details').html(data);
            jquery('#deleting').html(data);
        }
    });
    jQuery(document).ready(function(){
    jQuery.ajax({
        data: {
            exam_name: exam_name,
        },
        type: 'POST',
        url: 'student_site/studentcreate',
        success: function(data){
        //alert("inside change");
            console.log(data);
            jQuery('#crud').html(data);
            jquery('#deleting').html(data);
        }
    }); 
    });
}     

function CheckBoxVerification(From)
{
alert('hai');
    alert('hai:' $("table input[type=checkbox]:checked").length);
    if(From == "Insert")
    {
        if(!!$('#rowInsert input:checked').length == false)
        {
            alert('please select at least one check box to Create ...!');
        }
    }

    if(From == "Update")
    {
        if(!!$('#rowUpdate input:checked').length == false)
        {
            alert('please select at least one check box to Update ...!');
        }
    }
}
  function get_subjectdetails() {
    //var index = jQuery('#index').val();

    var course_name = jQuery('#course_name_id').val();

    //alert("course_name"+course_name);
    //var exam_name = jQuery('#course_name_id>option:selected').text();
    var exam_name = jQuery('#exam_name_id').val();
    var ssubject_code = jQuery('#ssubject_code_id').val();
    //var partsArray = exam_name.split('.');
    //alert("ssubject_code"+ssubject_code);
    //alert("course_name"+course_name);
    //alert("exam_name"+exam_name);
    jQuery.ajax({
        data: 'exam_name='+exam_name+'&course_name=' + course_name,
        type: 'POST',
        url: 'student_site/subject_records',
        success: function(data){
        //alert("inside change");
            console.log(data);
            //alert ("data"+data);
            //for(var j = course_name; j < ssubject_code; j++)
        //{
            jQuery('#ssubject_code').empty().append(data);
        //}
        }

    });
} 

</script>

<?php 
    $attributes=array(
        'name'=>'updatecustomer',
        'id'=>'updatecustomer'
        );
    echo form_open('student_site/manage_student',$attributes);
?>
<div id="validation_failed">
    <?php
        echo validation_errors();
    ?>
    <?php $data = array();
    if(isset($records)){
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } 

        $subject_data = array();
        foreach ($all_coursesubject_records as $row)
        {
            $subject_data[$row->subject_code] = $row->subject_code; 
        }  }


     ?>
     <div id="Processy ">
<table class="display table table-bordered table-striped" id='studenttable'>
<thead>
<tr font style='font-size:13px'>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Register Number</th>
<th>Name </th>
<th>Course Code</th>
<th>Subject Code</th>
</tr></thead>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr >
<td>
<?php echo anchor('student_site/delete/'.$row->id, 'Delete',array('onClick'=>"return confirm('Are you sure want to delete..?')")); ?>
</td>
<td id="rowUpdate">
<input type=checkbox name="editstudent[]" id="editstudent[]" value="<?php echo $row->id ?>">
</td>
<td ><input class="inputmedium span2" type="text" name="register_number_<?php echo $row->id ?>" id="register_number_<?php echo $row->id ?>" value="<?php echo $row->register_number; ?>" ></td>
<td ><input class="inputmedium span2" type="text" name="name_<?php echo $row->id ?>" id="name_<?php echo $row->id ?>" value="<?php echo $row->name; ?>" ></td>
//dropdown course code
<td >
<?php 

        $js = 'class="dropdown_class" id="course_code_id'.$row->id.'" onChange="get_subjectdetails112('.$row->id.')" '; 
        $js_name = 'course_code_id'.$row->id;
        echo form_dropdown($js_name, $data, $row->course_code, $js);
        echo"hai";
        print_r ($row->course_code);
?>
</td>
// drop down subject code
<td>    
<?php 

        $js = 'class="dropdown_class" id="subject_code_id'.$row->id.'"'; 
        $js_name = 'ssubject_code_id'.$row->id;
        echo form_dropdown($js_name, $subject_data, $row->subject_code, $js);
        var_dump($row->subject_code);
?>
<div id="ssubject_code<?php echo $row->id; ?>" ></div>
<input type="hidden" name="ssubject_code" id="ssubject_code" value="ssubject_code<?php echo $row->id; ?>"/>
</td>

</tr>
<?php endforeach; ?>
</table>
</div>
<center>
<input type="hidden" name="exam_name" id="exam_name" value="<?php echo $row->exam_name; ?>" />
<br /><input type="submit" class="btn-success btn" value="Update Student" onclick="CheckBoxVerification('Update')" id="start_button"></center>

<?php else : ?>
<h2>No records were returned.</h2>
<?php endif; ?>

查看:student_update

<script type="text/javascript" charset="utf-8">
function enableDisable(bEnable, textBoxID1, textBoxID2, chkBox)
{
    document.getElementById(textBoxID1).disabled = !bEnable
    document.getElementById(textBoxID2).disabled = !bEnable
    document.getElementById(chkBox).disabled = !bEnable
}
</script>

<script type="text/javascript" charset="utf-8">

 function get_subjectdetails112(index) {
 alert ("enter firstMAIN");
    //var index = jQuery('#index').val();
    //alert("index"+index);
    var course_name = jQuery('#course_code_id'+index).val();
    alert("course_name"+course_name);
    //var exam_name = jQuery('#course_name_id>option:selected').text();
    var exam_name = jQuery('#exam_name_id').val();
    var subject_code = jQuery('#subject_code_id'+index).val();
    alert(subject_code);
    //var partsArray = exam_name.split('.');
    //alert("ssubject_code"+ssubject_code);
    //alert("course_name"+course_name);
    //alert("exam_name"+exam_name);
    jQuery.ajax({
        data: 'exam_name='+exam_name+'&course_name=' + course_name,
        type: 'POST',
        url: 'student_site/update',
        success: function(data){
        //alert("inside change");
            console.log(data);
            //alert ("data"+data);
            //for(var j = course_name; j < ssubject_code; j++)
        //{
            jQuery('#subject_code_id'+index).empty().append(data);
        //}
        }

    });
} 
 function get_subjectdetails1(index) {
 alert ("enter first");
    //var index = jQuery('#index').val();
    //alert("index"+index);
    var course_name = jQuery('#course_name_id'+index).val();
    alert("course_name"+course_name);
    //var exam_name = jQuery('#course_name_id>option:selected').text();
    var exam_name = jQuery('#exam_name_id').val();
    var ssubject_code = jQuery('#ssubject_code'+index).val();
    //var partsArray = exam_name.split('.');
    //alert("ssubject_code"+ssubject_code);
    //alert("course_name"+course_name);
    //alert("exam_name"+exam_name);
    jQuery.ajax({
        data: 'exam_name='+exam_name+'&course_name=' + course_name,
        type: 'POST',
        url: 'student_site/subject_records',
        success: function(data){
        //alert("inside change");
            console.log(data);
            //alert ("data"+data);
            //for(var j = course_name; j < ssubject_code; j++)
        //{
            jQuery('#ssubject_code'+index).empty().append(data);
        //}
        }

    });
} 
 function student_updatedetails() {

        var register_number = jQuery('#register_number').val();
        var exam_name = jQuery('#exam_name_id').val();
        var name = jQuery('#name').val();
        var course_code = jQuery('#course_name_id').val();
        var subject_code = jQuery('#subject_name_id').val();
        //alert("register_number"+register_number+"name"+name+"exam_name: "+exam_name+"course_code"+course_code+"subject_code:"+subject_code);
        jQuery.ajax({
        data: 'exam_name=' + exam_name + '&register_number=' + register_number + '&name=' + name + '&course_code=' + course_code + '&subject_code=' + subject_code,
        type: 'POST',
        url: 'student_site/update',
        success: function(data){
            console.log(data);
            jQuery('#details').html(data);
        }
    });

} 

function CheckBoxVerification(From)
{
//alert('hi');
    if(From == "Insert")
    {
        if(!!$('#rowInsert input:checked').length == false)
        {
            alert('please select at least one check box to Create ...!');
        }
    }

    if(From == "Update")
    {
        if(!!$('#rowUpdate input:checked').length == false)
        {
            alert('please select at least one check box to Update ...!');
        }
    }
}
</script>

1 个答案:

答案 0 :(得分:1)

使用以下代码:

<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.js" ></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.min.js" ></script>
<section id="tables">
<script>
 jQuery(document).ready(function() {
  oTable = jQuery('#studenttable').dataTable({
   "bJQueryUI": true,
   "sPaginationType": "full_numbers"

  });
   }); 
  </script> 
  <script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
    jQuery.ajax({
        data: {
            exam_name: exam_name,
        },
        type: 'POST',
        url: 'student_site/studentcreate',
        success: function(data){
            console.log(data);
            jQuery('#crud').html(data);
            jquery('#deleting').html(data);
        }
    }); 
    });
 function get_studentdetails() {

    var exam_name = jQuery('#exam_name_id').val();
    jQuery.ajax({
        data: {
            exam_name: exam_name,
        },
        type: 'POST',
        url: 'student_site/studentupdate',          
        success: function(data){
            console.log(data);
            jQuery('#details').html(data);
            jquery('#deleting').html(data);
        }
    });

}     

function CheckBoxVerification(From)
{
alert('hai');
    alert('hai:' $("table input[type=checkbox]:checked").length);
    if(From == "Insert")
    {
        if(!!$('#rowInsert input:checked').length == false)
        {
            alert('please select at least one check box to Create ...!');
        }
    }

    if(From == "Update")
    {
        if(!!$('#rowUpdate input:checked').length == false)
        {
            alert('please select at least one check box to Update ...!');
        }
    }
}
  function get_subjectdetails() {
    var course_name = jQuery('#course_name_id').val();
    var exam_name = jQuery('#exam_name_id').val();
    var ssubject_code = jQuery('#subject_code_id').val();
    jQuery.ajax({
        data: 'exam_name='+exam_name+'&course_name=' + course_name,
        type: 'POST',
        url: 'student_site/subject_records',
        success: function(data){
            console.log(data);
            jQuery('#ssubject_code').empty().append(data);
        }

    });
} 

</script>

<?php 
    $attributes=array(
        'name'=>'updatecustomer',
        'id'=>'updatecustomer'
        );
    echo form_open('student_site/manage_student',$attributes);
?>
<div id="validation_failed">
    <?php
        echo validation_errors();
    ?>
    <?php $data = array();
    if(isset($records)){
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } 

        $subject_data = array();
        foreach ($all_coursesubject_records as $row)
        {
            $subject_data[$row->subject_code] = $row->subject_code; 
        }  }


     ?>
     <div id="Processy ">
<table class="display table table-bordered table-striped" id='studenttable'>
<thead>
<tr font style='font-size:13px'>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Register Number</th>
<th>Name </th>
<th>Course Code</th>
<th>Subject Code</th>
</tr></thead>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr >
<td>
<?php echo anchor('student_site/delete/'.$row->id, 'Delete',array('onClick'=>"return confirm('Are you sure want to delete..?')")); ?>
</td>
<td id="rowUpdate">
<input type=checkbox name="editstudent[]" id="editstudent[]" value="<?php echo $row->id ?>">
</td>
<td ><input class="inputmedium span2" type="text" name="register_number_<?php echo $row->id ?>" id="register_number_<?php echo $row->id ?>" value="<?php echo $row->register_number; ?>" ></td>
<td ><input class="inputmedium span2" type="text" name="name_<?php echo $row->id ?>" id="name_<?php echo $row->id ?>" value="<?php echo $row->name; ?>" ></td>
//dropdown course code
<td >
<?php 

        $js = 'class="dropdown_class" id="course_code_id'.$row->id.'" onChange="get_subjectdetails112('.$row->id.')" '; 
        $js_name = 'course_code_id'.$row->id;
        echo form_dropdown($js_name, $data, $row->course_code, $js);
        echo"hai";
        print_r ($row->course_code);
?>
</td>
// drop down subject code
<td>    
<?php 

        $js = 'class="dropdown_class" id="subject_code_id'.$row->id.'"'; 
        $js_name = 'ssubject_code_id'.$row->id;
        echo form_dropdown($js_name, $subject_data, $row->subject_code, $js);
        var_dump($row->subject_code);
?>
<div id="ssubject_code<?php echo $row->id; ?>" ></div>
<input type="hidden" name="ssubject_code" id="ssubject_code" value="ssubject_code<?php echo $row->id; ?>"/>
</td>

</tr>
<?php endforeach; ?>
</table>
</div>
<center>
<input type="hidden" name="exam_name" id="exam_name" value="<?php echo $row->exam_name; ?>" />
<br /><input type="submit" class="btn-success btn" value="Update Student" onclick="CheckBoxVerification('Update')" id="start_button"></center>

<?php else : ?>
<h2>No records were returned.</h2>
<?php endif; ?>