简体   繁体   English

在这种情况下如何预选一个选项?

[英]How to preselect an option in this case?

Hi I want to know how to preselect to option. 嗨,我想知道如何预选选项。 I think I can do it with javascript since I manage to get the countrycode but not the dropdown to get set appropriately: 我想我可以使用javascript做到这一点,因为我设法获取了国家代码,但没有下拉菜单来进行适当的设置:

在此处输入图片说明

In this case I want also the dropdodown to get populated to "England" which has the value GB. 在这种情况下,我还希望dropdowndown填充到值为GB的“ England”。 How can I do it? 我该怎么做? My JSP is: 我的JSP是:

<input type="text" class="inp_sel" size="2"
         name="<%=PandoraFieldConstants.FIELD_LANDKOD%>"
         id="<%=PandoraFieldConstants.FIELD_LANDKOD%>"
         value="<%if (ansokanInfo.getUppfinnareList().contains(editPerson)|| ansokanInfo.getSokandeList().contains(editPerson)){ out.write(editPerson.getLandKod());}%>"         
         onkeyup="setListbox(event, this, '<%=PandoraFieldConstants.FIELD_LAND%>')";
         onmousedown="setListboxEmpty(this)";>                                                 
         <SELECT name="<%=PandoraFieldConstants.FIELD_LAND%>" 
          id="<%=PandoraFieldConstants.FIELD_LAND%>"
          class="inp_sel" onChange="setSearchbox(this, '<%=PandoraFieldConstants.FIELD_LANDKOD%>')">
          <% for(LandKod land: pc.getLander()) { %> 
          <OPTION value="<%=land.getLandKod()%>"
          <% if (land.getLandKod().equalsIgnoreCase("SE")) {
          out.println("SELECTED");
          } %>

And my javascript is 我的JavaScript是

function setListbox(e, obj, id) {

     //               sokLandkod input
     //               sokLand select

     if(e.keyCode == 13 || e.keyCode == 8) { return; }
     if (obj.value.length < 2) { return; }

     var landList = document.getElementById(id);
     var searchKod = obj.value;
     var len = searchKod.length;
     obj.value = "";

     for (var i = 0; i < landList.options.length; i++) {

                       sListValue = landList.options[i].value;
                       var matchIx = sListValue.toUpperCase().indexOf(searchKod.toUpperCase());

     if (matchIx == 0) {
                       landList.selectedIndex = i;
                       obj.value = landList.options[i].value;
                       break;
     }
     }
}


function setSearchbox(obj, id) {

     var iny = 'sokLandkod'
     var searchKod = obj.value;
     document.getElementById(id).value = searchKod;
}

          ><%=land.getLandNamn() %>
          </OPTION>
          <% } %>
          </SELECT>

Can you advice me how to set the option? 您能建议我如何设置选项吗?

Thank you 谢谢

If England's value is "GB" ... you should change the following snippet to select "GB" and not "SE" (Is that the value of Sverige?): 如果England的值为“ GB” ,则应更改以下代码段以选择“ GB”,而不是“ SE” (这是Sverige的值吗?):

<% if (land.getLandKod().equalsIgnoreCase("SE")) { 
  out.println("SELECTED"); 
} %>

Unless, I misunderstood your data... It will look like this then. 除非,我误解了您的数据...然后看起来像这样。

<% if (land.getLandKod().equalsIgnoreCase("GB")) { 
  out.println("SELECTED"); 
} %>

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

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