2015-05-28 2 views
1

У меня есть один раскрывающийся список. Когда я выберу «Другие», «Другое текстовое поле действия».
Когда я выбираю «очные» или «О подготовке работы (OJT)», выпадающий «Предлагаемое обучение в Ilsas» и текстовое поле «Предлагаемое обучение в общественной» позволит.
Для «Другие» Состояние Я сделал все правильно.Как включить более одного условия в раскрывающемся списке?

Затем, как я могу добавить еще одно условие в JavaScript? Это потому, что я попытался объединить условия в JavaScript, но это не удалось.

<script language="javascript" type="text/javascript"> 
 
    function otherAction(val) { 
 
     var otherAct = document.getElementById('otherAct'); 
 
     if(val=='Others') { 
 
      otherAct.style.display = "block"; 
 
     } else {  
 
      otherAct.style.display = "none"; 
 
     } 
 
    } 
 
</script>
<table> 
 
    <tr> 
 
     <td>Action: </td> 
 
     <td> 
 
      <select name="perAction" onchange="otherAction(this.value)"> 
 
       <option value="0"></option>      
 
       <option value="Classroom Training">Classroom Training</option> 
 
       <option value="Coaches and Mentoring by IM">Coaches and Mentoring by IM</option> 
 
       <option value="On Job Training (OJT)">On Job Training (OJT)</option> 
 
       <option value="Others">Others</option> 
 
      </select> 
 
     </td> 
 
     <td>Other Action: </td> 
 
     <td><input name="otherAct" type="text" id="otherAct" /></td> 
 
     <td>Proposed Training in Ilsas: </td> 
 
     <td> 
 
      <select name = "perIlsas"> 
 
       <option value="0"></option>      
 
       <option value="Project Management">Project Management</option> 
 
       <option value="Contract Management">Contract Management</option> 
 
       <option value="Analytical Skill">Analytical Skill</option> 
 
      </select> 
 
     </td> 
 
     <td>Proposed Training in Public: </td> 
 
     <td><input name="pubTraining" type="text" id="pubTraining" /></td> 
 
    </tr> 
 
</table>

+0

<выбрать несколько> – Kristiyan

ответ

1

Вы просто должны использовать несколько if-else условия

<script language="javascript" type="text/javascript"> 
    function otherAction(val) { 
     var otherAct = document.getElementById('otherAct'); 
     if(val=='Others') { 
      otherAct.style.display = "block"; 
     } else if(val == 'On Job Training (OJT)'){  
      otherAct.style.display = "none"; 
      pubTraining.style.display = "block"; 
      // set display here either `block` or `none` according to your need 
     } 
     else{ 
      // set display here either block or none according to your need 
     } 
    } 
</script> 

EDIT: Прежде всего дать некоторые id атрибут этого выберите поле. а затем, Вы можете написать проверки другого else-if состояние как этот

<select id="perIlsas" name = "perIlsas"> //assigning id attribute 

else if(val == 'Coaches and Mentoring by IM'){ //another else-if condition  
     $('#perIlsas').prop('disabled', 'disabled'); //this will disable entire selectbox 
     } 

Вы можете узнать больше о prop в jQuery Docs

+0

TQ. Это то, чего я действительно хочу. Но почему droplinelist perIlsas не может отключиться, когда я выбираю «Тренеры и наставничество» с помощью IM? Работает только текстовое поле для pubTraining. –

+0

hi..checkout edit – Abhinav