Display checked checkbox names without form tag

Hi everyone …:). I have problem in my program.

I have hashmap i.e. collection ,

my code is as follows


<%! private HashMap<Integer, Domain>domainmap; %>
<%
domainmap=(HashMap<Integer,Domain>)session.getAttribute("domainmap");
%>
<table border="1">
			<c:forEach var="domain" items="${domainmap}">
				<tr><td>
				<input type=checkbox  name="check" id="checkId" value="${domain.value.domainName}"/>
				<c:out value="${domain.value.domainName}"></c:out>
				</td></tr>
			</c:forEach>

</table>


so, i want to display all seleced checked checkbox names, when i click on button but without using FORM tag… please, waiting for your reply

Are you trying to get the “name” attribute of the checked checkbox? Are you using jquery? If yes then it is really simple…

jquery


<script type="text/javascript">

$(document).ready(function() {
    
    $("#getnames").click(function(){
        var checkedNames = '';
        $("input[type='checkbox']:checked").each(function(){
            checkedNames = checkedNames != '' ? checkedNames+', ' : checkedNames;
            checkedNames += $(this).attr("name");
        });
        alert(checkedNames);
        return false;
    });

});
</script>

HTML


<table>
        <tr>
            <td witdh="50px"><input name="one" type="checkbox" value="G" /></td>
            <td witdh="200px">One</td>
        </tr>
        <tr>
            <td witdh="50px"><input name="two" type="checkbox" value="G" /></td>
            <td witdh="200px">Two</td>
        </tr>
        <tr>
            <td witdh="50px"><input name="three" type="checkbox" value="G" checked="checked" /></td>
            <td witdh="200px">Three</td>
        </tr>
        <tr>
            <td witdh="50px"><input name="four" type="checkbox" value="G" /></td>
            <td witdh="200px">Four</td>
        </tr>
        <tr>
            <td witdh="50px"><input name="five" type="checkbox" value="G" checked="checked" /></td>
            <td witdh="200px">Five</td>
        </tr>
        <tr>
            <td witdh="50px"><input name="six" type="checkbox" value="G" /></td>
            <td witdh="200px">Six</td>
        </tr>
    </table>

    <a href="#" id="getnames">get names</a>

What does the generated HTML look like? JavaScript interacts with the HTML the browser sees and not with the server side language that is run on the server to generate the HTML.

Also it is invalid HTML for an <input> field to not be wrapped in side a block level tag that is in turn wrapped in a <form> tag (unless you are writing HTML 3.2 in which case the <input> tag may be directly inside the <form> tag).