3 Replies - 1105 Views - Last Post: 10 August 2012 - 01:55 PM

#1 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

javascript clear all checkbox?

Posted 10 August 2012 - 12:46 PM

I cannot figure out how this works:

<div class="dx"><a href="javascript:void(0);" id="jq_clear" class="more" title="ClearAll">ClearAll</a></div>


When I click the ClearAll link, all checkboxes on the page are unchecked. I cannot find "jq_clear", "ClearAll", "dx" or even "more" anywhere else in the page source. I looked up "javascript:void(0);" but it just prevents reload? how can the link be rendered?

Is This A Good Question/Topic? 0
  • +

Replies To: javascript clear all checkbox?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,771
  • Joined: 27-December 08

Re: javascript clear all checkbox?

Posted 10 August 2012 - 12:47 PM

Moved to Javascript.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: javascript clear all checkbox?

Posted 10 August 2012 - 01:40 PM

Most likely the link's click event is being capture in a Javascript script somewhere, either in the main HTML file, or in an external Javascript file.

For example, if I were to create a file called myScript.js, who's content's are:
// Wait until the window has finished loading.
window.addEventListener("load", function() {
    // Get a reference to the link.
    var theLink = document.getElementById("jq_clear");
    
    // Listen for the links "click" event.
    theLink.addEventListener("click", function() {
        // Find all checkboxes on the page. (This doesn't
        // work in old versions of IE. (IE7 and lower.)
        // Other solutions are needed for them.)
        var boxes = document.querySelectorAll("input[type='checkbox']");
        
        // Uncheck them all.
        for (var i = 0; i < boxes.length; ++i) {
            boxes[i].checked = false;
        }
    }, false);
}, false);


And then load it into the main HTML by doing:
<script src="myScript.js" type="text/javasript"></script>


Then every time the link is clicked, all checkboxes are unchecked.
Was This Post Helpful? 1
  • +
  • -

#4 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: javascript clear all checkbox?

Posted 10 August 2012 - 01:55 PM

in that case, if src=(absolute path), my locally saved html will work. if my locally save html does not work, it means the site uses src=(relative path)?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1