2013-05-30 50 views
1

我有一张桌子,当我点击某一行时,我希望将此行的值打印在窗体上,其中有一个组合框。 因此,我可以改变组合中的选项的文本不会自动选择一个选项的问题?根据文本自动在Combobox中选择一个值

这是我的剧本,但它并没有给我什么,我想:

var fvar=document.forms.f.fonction; 

    for(var i=0;i<fvar.options.length;i++){ 
     if (document.getElementById('listuser') 
     .getElementsByTagName('tr')[row.rowIndex].cells[2].textContent==fvar.options[i].text) 
      { 
      fvar.options[i].selected=true; 
      } 
    } 

的HTML:

<table id="listuser"> 

    <thead> 
     <tr> 
      <th>Action</th> 
      <th>Code</th> 
      <th>Fonction</th> 

     </tr> 


     <tr id="lign" onClick="selectRowService(this)"> 
      <td><input type="checkbox" name="box"></td> 
      <td><c:out value="${activity.cd_activite}" /></td> 
      <td><c:out value="${activity.fonction}" /></td> 
    </thead> 


    <!-- Table body --> 

    <tbody> 
    </tbody> 

</table> 

<table id="tabmenu"> 

    <tr> 
     <td>Fonction :</td> 
     <td><div class="styled-select"> 
       <form:select name="fonction" path="fonction"> 

        <c:forEach items="${fonc}" var="f"> 
         <form:option value="${f.code_fonction}">${f.ll_fonc}</form:option> 
        </c:forEach> 

       </form:select> 
      </div></td> 
    </tr> 

</table> 

请是否有任何其他的方式来自动选择期权的价值?

回答

1

试试这个

var fvar=document.forms.f.fonction; 

    for(var i=0;i<fvar.options.length;i++){ 
     if (document.getElementById('listuser') 
     .getElementsByTagName('tr')[row.rowIndex].cells[2].textContent==fvar.options[i].text) 
      { 
       fvar.value = fvar.options[i].value; 
      } 
    } 
+0

它的作品。谢谢! – Somar

相关问题