SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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

    Code:
    <%! 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

  2. #2
    Learning...
    Join Date
    Jan 2003
    Posts
    781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to get the "name" attribute of the checked checkbox? Are you using jquery? If yes then it is really simple...

    jquery
    Code:
    <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
    Code:
    <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>
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •