简体   繁体   English

从下拉列表中将选定的目标删除到另一个下拉列表

[英]Remove selected destination from dropdown list to another dropdown list

I am currently developing an airline reservation using PHP(Codeigniter). 我目前正在使用PHP(Codeigniter)开发机票预订。 Currently the fields/radio buttons that I have: 目前,我拥有的字段/单选按钮:

2 radio button 2个单选按钮

1) One way 1)一种方式

2) Round Trip 2)往返

2 dropdown list 2下拉列表

1) From 1)从

2) To 2)至

and so on.. 等等..

When the user trying to book, the user can't repeat the destination he inputted "from destination" into "to destination". 当用户尝试预订时,用户无法重复输入“从目的地”到“到目的地”的目的地。 Example: I have 3 destinations; 示例:我有3个目的地; 1) Country 1; 1)国家1; 2) Country 2; 2)国家2; 3) Country 3, then user tries to book. 3)国家3,然后用户尝试预订。 From: Country 1, To: Country1. 从:国家1,到:国家1。 The Country 1 in the "To:" should not be display because he already use it in the From Destination. 不应显示“收件人:”中的国家1,因为他已在“发件人目的地”中使用它。

NOTE: The thing that I do first is, call all the available destinations in my controller then call it in my view using my foreach. 注意:我首先要做的是,在控制器中调用所有可用的目标,然后在我的视图中使用foreach对其进行调用。

<div class="pure-u-1-1 fromto">
               <div class="pure-u-1-1">
                  <label for="from" class="margin2px">From</label>
                  <!-- <input type="text" class="fromto"><br> -->
                  <select class="fromto" name="flight_from">
                  <?php foreach($flight as $a):?>
                    <option value ="<?= $a->flight_name?>" ><?= $a->flight_destination?></option>
                  <?php endforeach?>

                  </select>

               </div>
                <div class="pure-u-1-1">
                  <label for="to" class="tomargin">To</label>
                  <!-- <input type="text" class="fromto"><br> -->
                  <select class="fromto" name="flight_to">
                    <?php foreach($flight as $a):?>
                      <option value ="<?= $a->flight_name?>" ><?= $a->flight_destination?></option>
                    <?php endforeach?>
                  </select>
                </div>

Question: How can I prevent it from repeating the country I selected in my "from destination" into "to destination"? 问题:如何防止其将在“从目的地”中选择的国家重复到“到目的地”?

You may use jQuery: 您可以使用jQuery:

 $('select[name=flight_from]').on('change',function(){ $("select[name=flight_to]").find('option').show(); var from = $(this).find(":selected").val(); $("select[name=flight_to]").val(''); if ( from != "" ) { $("select[name=flight_to]").find( 'option:contains("'+from+'")' ).hide(); } }) 
 <select name="flight_from"> <option value="">-- Please select depature --</option> <option>Country 1</option> <option>Country 2</option> <option>Country 3</option> </select> <select name="flight_to"> <option value="">-- Please select destination --</option> <option>Country 1</option> <option>Country 2</option> <option>Country 3</option> </select> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM