簡體   English   中英

codeigniter下拉順序,第一個下拉菜單中選擇的值不會在第二個出現

[英]codeigniter dropdown order, value chosen on first dropdown musn't apear on 2nd one

我需要在健身房中設置四項運動選項,所以我必須使用四個下拉菜單,我已經從數據庫中檢索數據列表,這是一個數組drom數據庫,當我在第一個中選擇第一個時,它包含30個學科下拉第二個下拉菜單中將不包含此值,並且當我從第三個下拉列表中選擇一個值時,該下拉列表將不包含dropdown1和dropdown2中的value1和value2,下拉菜單四也必須包含來自其中的27個值數據庫

我的模型:參與者port_m.php:

  public function get_new()

{

$participant_sport = new stdClass();

$participant_sport->nom = '';
$participant_sport->prenom = '';
$participant_sport->trimestres = '';
$participant_sport->sport_ordre1 = '';
$participant_sport->sport_ordre2 = '';
$participant_sport->sport_ordre3 = '';
$participant_sport->sport_ordre4 = '';
$participant_sport->sport_montant_paye = '';
$participant_sport->sport_debut_periode = '';
$participant_sport->sport_fin_periode = '';
  return $participant_sport;
}


    function get_discipline_sport() {
            $this ->db->select('id, nom_discipline');
            $query = $this ->db->get('disciplines_sport');

            $salles = array();

            if ($query->result()) {
                    foreach ($query->result() as $discipline) {
                      $disciplines[$discipline->id] = $discipline->nom_discipline;
                    }
                    return $disciplines;
            } else {
                    return FALSE;
            }
    }

數據庫的結構:id-nom_discipline-tarif_discipline-說明

我的控制器agent.php:

        public function inscriresport ($id = NULL)
        {

            // Fetch a participant or set a new one
            if ($id) {
                $this->data['participant_sport'] = $this->participantsport_m->get($id);
                count($this->data['participant_sport']) || $this->data['errors'][] = 'Agent non trouvé';

            // explode to array
            // print_r($this->data['participant_sport']['trimestres[]']); // test before explode

              $this->data['participant_sport']->trimestres = explode(",", $this->data['participant_sport']->trimestres);

            // print_r($this->data['participant_sport']['trimestres[]']); // test after explode
            }
            else {
                $this->data['participant_sport'] = $this->participantsport_m->get_new();
            }

            // Set up the form
            $rules = $this->participantsport_m->rules_participantsport;
            $this->form_validation->set_rules($rules);

            // Process the form

            if ($this->form_validation->run() == TRUE) {
                $data = $this->participantsport_m->array_from_post(array('nom', 'prenom', 'beneficiaire', 'trimestres' , 'sport_ordre1', 'sport_ordre2', 'sport_ordre3', 'sport_ordre3',  ,'sport_montant_paye', 'sport_debut_periode', 'sport_fin_periode'));
                $this->participantsport_m->save($data, $id);
                redirect('admin/agent/profile/3608');
            }

            // Load the view
            $this->data['subview'] = 'admin/agent/inscriresport';
            $this->load->view('admin/_layout_main', $this->data);
       }

和我的看法inscriresport.php:

                    <div class="widget-box">
                        <div class="widget-title">
                            <span class="icon">
                                <i class="icon-align-justify"></i>                                  
                            </span>
                            <h5><?php echo empty($participant->id) ? 'Nouveau Agent OCP:' : 'Modification de: ' . $participant_sport->nom.' '.$participant_sport->prenom; ?></h5>
                        </div>

                        <div class="widget-content nopadding">

                            <?php echo form_open(); ?>



                  <div  <?php if(form_error('nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                    <label class="control-label">Nom :</label>
                    <div class="controls">
                       <?php echo form_input('nom', set_value('nom', $this->input->get('nom') )); ?>
                       <span class="help-inline"><?php echo form_error('nom'); ?></span>
                    </div>
                  </div>


                  <div  <?php if(form_error('prenom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                    <label class="control-label">Prenom :</label>
                    <div class="controls">
                       <?php echo form_input('prenom', set_value('prenom', $this->input->get('prenom') )); ?>
                       <span class="help-inline"><?php echo form_error('prenom'); ?></span>
                    </div>
                  </div>




                        <div  <?php if(form_error('beneficiaire')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Bénéficiaire :</label>
                          <div class="controls">

                                                  <label><?php echo form_radio('beneficiaire', 'Agent', $this->input->get('beneficiaire') == 'Agent') ?> Agent </label>

                                                  <label><?php echo form_radio('beneficiaire', 'Conjoint', $this->input->get('beneficiaire')  == 'Conjoint') ?> Conjoint </label>

                                                  <label><?php echo form_radio('beneficiaire', 'Enfant', $this->input->get('beneficiaire')  == 'Enfant') ?> Enfant </label>
                                                  <span class="help-inline"><?php echo form_error('beneficiaire'); ?></span>
                          </div>
                        </div>




              <div <?php if(form_error('trimestres[]')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Trimestres :</label>
                      <div class="controls" >

                      <?php $options = array(
                                          'trim1'  => ' Premier trimestre (Janv,Fév,Mars)',
                                          'trim2'    => ' Deuxiéme trimestre (Avril,Mai,Juin)',
                                          'trim3'   => ' Troisiéme trimestre (Juill,Aout,Sept)',
                                          'trim4' => ' Quatriéme trimestre (Oct,Nov,Déc)',
                                        );
                     echo form_multiselect('trimestres[]', $options , $this->input->post('trimestres') ? $this->input->post('trimestres') : $participant_sport->trimestres, 'id="trim"'); ?>
                      <span class="help-inline"><?php echo form_error('trimestres[]'); ?></span>
                  </div>
              </div>


              <div <?php if(form_error('sport_ordre1')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre1', $countries , $this->input->post('sport_ordre1') ? $this->input->post('sport_ordre1') : $participant_salle->sport_ordre1 , 'id="ordre1"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre1'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre2')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre2', $countries , $this->input->post('sport_ordre2') ? $this->input->post('sport_ordre2') : $participant_salle->sport_ordre2 , 'id="ordre2"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre2'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre3')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre3', $countries , $this->input->post('sport_ordre3') ? $this->input->post('sport_ordre3') : $participant_salle->sport_ordre3 , 'id="ordre3"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre3'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre4')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre4', $countries , $this->input->post('sport_ordre4') ? $this->input->post('sport_ordre4') : $participant_salle->sport_ordre4 , 'id="ordre4"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre4'); ?></span>
                  </div>
              </div>




                        <div  <?php if(form_error('sport_montant_paye')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Montant à payé :</label>
                          <div class="controls">
                             <?php echo form_input('sport_montant_paye', set_value('sport_montant_paye', $participant_sport->sport_montant_paye)); ?>
                             <span class="help-inline"><?php echo form_error('sport_montant_paye'); ?></span>
                          </div>
                        </div>






                        <div  <?php if(form_error('sport_debut_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Debut période :</label>
                          <div class="controls">
                             <input type="text" name="sport_debut_periode" id="date3" value="<?php echo set_value('sport_debut_periode', $participant_sport->sport_debut_periode) ?>" />
                             <span class="help-inline"><?php echo form_error('sport_debut_periode'); ?></span>
                          </div>
                        </div>




                        <div  <?php if(form_error('sport_fin_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Fin période :</label>
                          <div class="controls">
                             <input type="text" name="sport_fin_periode" id="date4" value="<?php echo set_value('sport_fin_periode', $participant_sport->sport_fin_periode) ?>" />
                             <span class="help-inline"><?php echo form_error('sport_fin_periode'); ?></span>
                          </div>
                        </div>






                                <div class="form-actions">
                                    <?php echo form_submit('submit', 'Enregistrer', 'class="btn btn-success"'); ?>
                                </div>
                            <?php echo form_close();?>

                        </div>
                    </div>

                </br>

我需要如何通過javascript做到這一點,所以我是javascript的新手,我不知道該從哪里開始,請幫忙嗎? 非常感謝。

我建議在所有下拉菜單中包括所有體育項目,當您要提交表格時,請檢查是否有相同價值的下拉菜單。 您可以通過以下方式獲得它們:

var flag = false;

var e1 = document.getElementById("dropdown1 id");
var value1 = e1.options[e1.selectedIndex].value;

var e2 = document.getElementById("dropdown2 id");
var value2 = e2.options[e2.selectedIndex].value;

...

if(value1 != value2 && ...)
{
  flag = true;
}

if(flag)
{
  // Stuff
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM