开发者

Remove one option from dropdown based on the option selected in the before dropdown list

Here is my HTML Code.

   <table>
   <tr>
   <td>
   <select class="dropdown">
   <option value="">Select answer</option>
   <option value="1" selected="selected">A</option>
   <option value="2">B</option>
   <option value="3">C</option>
   </select>
   </td>
   <td>
   <select class="dropdown">
   <option value="">Select answer</option>
   <option value="1" >Yes</option>
   <option value="2">No</option>
   <option value="3">N.A.</option>
   </select>
   </td>
   </tr>
   <td>
   <select class="dropdown">
   <option value="">Select answer</option>
   <option value="1" >Yes</option>
   <option valu开发者_开发技巧e="2">No</option>
   <option value="3">N.A.</option>
   </select>
   </td>
   </table>

Here is my jquery code.

                     $('TABLE TR').find('select:first').each(function()
                     {
                      if($(this).find("option:selected").text()=="A")
                      {
                        $(this).next("select").find("option[value='Yes']").remove();
                      }
                     });

I want to remove the immediate next drop down value based on the value of first dropdown box. Please someone help..


Try this jQuery:

$('TABLE TR select:first').each(function() {
    if($(this).find("option:selected").text()=="A")
    {
        $('TABLE TR select:eq(1)').find("option[value='1']").remove();
    }
});

This code will delete "Yes" option from the second dropdown. It seems that it is exactly what you want.


try this

  $('TABLE').find('select:first').change(function()
                 {
                  if($(this).find("option:selected").text()=="A")
                  {  $('Table').find('Select').eq(1).find("option[value='1']").remove();
                  }
                 });


Replace your jquery code line #5

$(this).next("select").find("option[value='Yes']").remove();

With

$('TABLE TR select:eq(1)').find("option[value='1']").remove();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜