2

我有以下表格:

<s:form id="storno_form"
    namespace="namespace"
    action="action">

    <sj:submit id="submitId"
        key="btn.show" targets="cancelation_content"
        cssClass="button" validate="true">
    </sj:submit>
</s:form>

形式之外是:

<sj:select
    href="%{getUrl}"
    id="selectCampaign"
    autocomplete="true"
    selectBoxIcon="true"
    key="select.campaign"
    name="campaignId"
    list="campaigns"
    listKey="id"
    listValue="name"
    headerKey="-1"
    headerValue="%{getText('select.headerValue')}"
    onSelectTopics="realod"
    onCompleteTopics="customizeAutoCompleter"
/>

如何使用表单提交选择元素的值:我尝试过:

<s:form id="storno_form"
    namespace="namespace"
    action="action">
    <s:hidden  value="%{'campaignId'}" name="campaignId" />
    <sj:submit id="submitId"
        key="btn.show" targets="cancelation_content"
        cssClass="button" validate="true">
    </sj:submit>
</s:form>

但它不工作?

4

1 回答 1

3

你可以用javascript做到这一点

onchange="var el=document.getElementById('selectCampaign');document.getElementById('storno_form')['campaignId'].value=el.options[el.selectedIndex].value;"

同样你可以做标签onclick事件。<sj:submit

使用 jQuery 更容易

$(document).ready(function() {
  $('#selectCampagn').change(function() {
   var val = $('#selectCampagn').val();
    $('input[name=campaignId]').val(val);
  });
});
于 2013-05-03T10:49:45.293 回答