简体   繁体   English

如何仅提交选中的复选框

[英]how to submit only checked checkboxes

I want to add a "submit" button that submits only the checked checkboxes. 我想添加一个“提交”按钮,仅提交选中的复选框。 I don't know how to pass only the checked ones to the server. 我不知道如何仅将已检查的内容传递给服务器。 thanks. 谢谢。

The Button: 按钮:

<a:commandButton id="saveAllBtn" value="Submit All" style="width: 60px; cursor:pointer" action="#{urlAction.saveAll()}"
reRender="qualificationForm,messages"
disabled="#{urls.rowCount==0}" requestDelay="100"
onclick=" disableOperations();beforeRedirect();"
onfocus="highlightButton(this);" onblur="unhighlightButton(this);"
actionListener="#{growlBean.save}">
</a:commandButton>

The checkboxes: 复选框:

<div id="urlsContainer" class="list-group"
    style='width: 350px; word-wrap: break-word; margin-top: 10px'>
    <a:repeat value="#{urlAction.urlsIndexList}" var="_urlIndex">
    <a href='#' class='list-group-item'
    style='float: left; width: 350px; height: 50px;'>
    <input type='checkbox' class="urlCheckBox" name='checkbox-1'
    style='margin-left: 15px; float: left;'>
    <span style='margin-left: 10px; font-size: 12px; float: left; 
    word-break: break-all; width: 300px;' 
    onclick='showFraim("#{_urlIndex}")'>#{urlAction.getUrl(_urlIndex)}
    </span>
    </input>
    </a>
    </a:repeat>
</div>

I have all the URLs in a list named "urls" in a java class named urlAction. 我在名为urlAction的java类中的名为“ urls”的列表中拥有所有URL。

Example: 例:

[x]  www.google.com
[ ]  www.yahoo.com
[x]  www.nytimes.com

If I checked the first and third what would be submitted are: 如果我检查了第一个和第三个,将提交的内容是:

www.google.com
www.nytimes.com

By default only the checked checkboxes are sent. 默认情况下,仅发送选中的复选框。 You do need to give the checkboxes a value, for instance value="1" . 您确实需要为复选框提供一个值,例如value="1"

<input type='checkbox' class="urlCheckBox" name='checkbox-1'
style='margin-left: 15px; float: left;' value="1">

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

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