我需要在健身房设置一个四阶运动选项,所以我必须使用四个下拉菜单,我从数据库中检索数据列表,这是一个阵列drom数据库,当我选择fisrt一个包含30个学科在第一个下拉列表中,seconde下拉列表不包含这个值,而且当我从第3个下拉列表中选择一个值时,这个下拉列表不会包含来自dropdown1和dropdown2的value1和value2,同样关于下拉列表4它必须只包含来自数据库的27个值
我的模特:participantport_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 - description
我的控制器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的新手,我不知道我从哪里开始,任何帮助plsease?非常感谢。
答案 0 :(得分:0)
我建议在所有下拉列表中包含所有体育项目,当您想要提交表单时,请检查是否有任何相同的值下拉列表。你可以通过以下方式获得它们:
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
}