0
  <form method="get" action="processform.php">
  <b>SELECT SERVICE</b><select name="Service">
  <option value="">Select a Service</option>
  <option value="toairport">To Airport</option>
  <option value="fromairport">From Airport</option>
  <option value="DriveAround">Drive Around</option>
  <option value="PointToPoint">Point TO Point</option>
  <option value="Wedding">Wedding</option>
  <option value="Prom">Prom</option>
  <option value="Graduation">Graduation</option>
  <option value="Birthday">Birthday</option>
  <option value="Concert">Concert</option>
  <option value="SportingEvents">Sporting Events</option>
  <option value="Anniversary">Anniversary</option>
  </select>

   Airports<select name="airports">
  <option value="">Select an Airport</option>
  <option value="LGA">LaGuardia</option>
  <option value="JFK">Jonh F. Kennedy</option>
  <option value="Westchester">Westchester</option>
  <option value="Terteboro">Terteboro</option>
  <option value="Islip">Islip</option>
  </select>

I have the above code, In the service section when i click "from airport or to airport i wan the Airport option to show. thanks in advance

4

3 回答 3

1

我建议:

$('select[name="Service"]').change(function(){
    var v = $(this).val().toLowerCase();
    $('select[name="airports"]').toggle((v == 'toairport' || v == 'fromairport'));
}).change();

JS 小提琴演示

您还可以使用简单的正则表达式来测试value以单词结尾airport(与发布的要求相匹配,因为您要测试的两个选项都以字符串“airport”结尾):

$('select[name="Service"]').change(function(){
    var v = $(this).val().toLowerCase();
    $('select[name="airports"]').toggle(v.match(/airport$/));
}).change();

JS 小提琴演示

参考:

于 2013-07-01T14:49:54.947 回答
0

尝试这个

$("select[name=Service]").change(function(e){
    if(e.target.value == "toairport" || e.target.value == "fromairport"){
        $("select[name=airports]").show();
    }else{
        $("select[name=airports]").hide();
    }
})
于 2013-07-01T14:42:08.510 回答
0

你可能正在寻找这个:

$("#airports").hide()
$("#service").change(function(){
    if(this.value == 'toairport' || this.value == 'fromairport')
       $("#airports").show();
    else
        $("#airports").hide();
});

标记:

<select name="Service" id="service">
<select name="airports" id="airports">

演示--> http://jsfiddle.net/jA56n/

于 2013-07-01T14:43:15.057 回答