Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:20:47+00:00 2026-05-23T05:20:47+00:00

I have this html code: <c:forEach items=${config.sources} var=source varStatus=sourceStatus> <form:checkbox path=sources[${sourceStatus.index}].selected label=${source.sourceName} name=${sourceStatus.index} onclick=toggle(this)/>

  • 0

I have this html code:

        <c:forEach items="${config.sources}" var="source" varStatus="sourceStatus">
            <form:checkbox path="sources[${sourceStatus.index}].selected" 
            label="${source.sourceName}" 
            name="${sourceStatus.index}"
            onclick="toggle(this)"/>
            <br />
            <c:forEach items="${source.feeds}" var="feed" varStatus="status">
                <c:if test="${feed.display == true }">  
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <form:checkbox path="sources[${sourceStatus.index}].feeds[${status.index}].selected" name="${sourceStatus.index}"/>
                    <c:out value="${feed.name}" /> (provided by ${feed.provider})
                <br />
                </c:if>
            </c:forEach>
        </c:forEach>

What it does is make a bunch of checkboxes, where if the “main” checkbox becomes selected, it call the javascript method “toggle”, which should select all the “sub” checkboxes for that “main” checkbox. Here is the javascript:

<script type="text/javascript">
    function toggle(chkbox) {

    if (chkbox.checked) {
            var x = document.getElementsByName(chkbox.name);
            for ( var i in x) {
                if (!x[i].checked)
                    x[i].click();
                alert("HEY!" + x[i].name);
            }
        } else if (!chkbox.checked) {
            var x = document.getElementsByName(chkbox.name);
            for ( var i in x) {
                if (x[i].checked)
                    x[i].click();
                alert("HEY!" + x[i].name);
            }
        }
    }
</script>

However, while the “main” checkbox get’s checked, none of its “sub” boxes get checked. Furthermore, when the alert goes off after the “main” has been selected, only ONE alert goes off, presumably for the “main” box, and it does not print out an index like expected, instead it says, “sources[X].selected” where X is the index. Furthermore, when deselected, it has four alerts, regardless of the number of “sub” boxes. They always say, “sources[X].selected”, “undefined”, “item”, and “namedItem”, respectively. WTH is going on??! I must be doing something very wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:20:48+00:00Added an answer on May 23, 2026 at 5:20 am

    Ok, so the problem for me was the jsp reserves almost every settable variable. Because of this, one cannot use name, or id, or anything like that to identify the checkboxes. What I ended up doing was this:

    JSP:

            <input type="checkbox" value="false"
                label="Select/Deselect All" title="-1"
                onclick="toggle(this, '-1')" />
            <br />
            <c:forEach items="${config.sources}" var="source"
                varStatus="sourceStatus">
                <form:checkbox path="sources[${sourceStatus.index}].selected"
                    label="${source.sourceName}" title="${sourceStatus.index}"
                    onclick="toggle(this, ${sourceStatus.index})" />
                <br />
                <c:forEach items="${source.feeds}" var="feed" varStatus="status">
                    <c:if test="${feed.display == true }">  
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <form:checkbox
                            path="sources[${sourceStatus.index}].feeds[${status.index}].selected"
                            title="${sourceStatus.index}" />
                        <c:out value="${feed.name}" /> (provided by ${feed.provider})
                    <br />
                    </c:if>
                </c:forEach>
            </c:forEach>
    

    Javascript:

    function toggle(chkbox, title) {
        var y = document.getElementsByTagName("input");
        var xIndex = 0;
        var x = new Array();
        for (var i = 0; i < y.length; ++i) {
            if((y[i] != null) && (y[i].title == title || title == -1)){
                x[xIndex] = y[i];
                xIndex++;
            }
        }
    if (chkbox.checked) {
            for (var i = 0; i < x.length; ++i) {
                x[i].checked = true;
            }
        } else {
            for (var i = 0; i < x.length; ++i) {
                x[i].checked = false;
            }
        } 
    }
    

    Title was the only editable field that jsp did not use I could find. Sad, I know, but oh well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML code which simulates a dropdown multi-checkbox <div> <div class=select> <span>Select
I have this HTML code multiple times one after the other: <li> <img src=path/to/my/picture.jpg
I have this HTML code for radios: <input type='radio' name='a_27' value='Yes' id='a_27_0' /> <input
I have this html code that i want to edit with jQuery. Here is
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have this HTML code: <div class='com_box'> <div class='com_box_c'> <div class='com_box_info'> <a id='quote'>quote</a> </div>
I have this HTML code: <div id=main> <div id=dv_7>...</div> <div id=dv_1>...</div> <div id=dv_8>...</div> <div
I have this html code: <div class=action> some_text <a class=delete_action name=q1>some</a> </div> <div class=action>
I have this piece of HTML code: <tr class=AttCardFooter onMouseOver=this.style.backgroundColor='#E1EAFE' onMouseOut=this.style.backgroundColor='Transparent'>...etc etc.. new lines
OK i have this code HTML: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js> </script> <script type=text/javascript>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.