how to submit only checked checkboxes

1.7k views Asked by At

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.

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
1

There are 1 answers

0
Halcyon On BEST ANSWER

By default only the checked checkboxes are sent. You do need to give the checkboxes a value, for instance value="1".

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