Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>.split()</code> is a function you can execute on a string object, to split it up in pieces, depending on a parameter provided:<br> <code>"abcdefg|hijklmnop|qrstuvw".split('|')</code><br> would result in a array like this:<br> <code>["abcdefg","hijklmnop","qrstuvw"]</code></p> <p>Now, I am guessing you have added a "?showpastdate" parameter to the url, to change a checkbox's "checked" status. The easiest way to do that would be: </p> <pre><code>document.getElementById("showpastdate").checked = (~window.location.href.indexOf("?showpastdate")) </code></pre> <p>This part: <code>window.location.href.indexOf("?showpastdate")</code> Searches the href for<br> <code>"?showpastdate"</code><br> If the string has been found, it will return a index. if not, it will return -1. The squiggly in front of it is to convert the -1 or 0 (or higher) to a true / false.</p> <p>I'm not quite sure what the <code>toggleAutoRefresh()</code> is supposed to do, though</p> <h1>Edit 1</h1> <p>Ah, for the <code>toggleAutoRefresh()</code>, just add this:</p> <pre><code>if (cb.checked) { window.location.href.replace("?showpastdate",""); } </code></pre> <p>instead of that <code>if-else</code> block you have there. The <code>.replace()</code> function works on a string the same way <code>.split()</code> does. It takes 2 arguments: What to look for, and what to replace it with. So, for example:</p> <pre><code>var someString = "words and stuff" var result = someString.replace(" ","_"); //result will be "words_and_stuff" </code></pre> <h1>Edit 2</h1> <p>These functions should work:</p> <pre><code>function checkReloading() { document.getElementById("showpastdate").checked = (~window.location.href.indexOf("?showpastdate")) } function toggleAutoRefresh(cb) { if (cb.checked) { window.location.href.replace("?showpastdate",""); }else{ window.location.href += "?showpastdate"; } } </code></pre> <p>Where are you calling toggleAutoRefresh() from?</p> <h1>Edit 3</h1> <p>What I can conclude from your last comment, is that you want to do something like this:</p> <pre><code>// If a checkbox named "cb" is checked, and the url contains "?showpastedate" if ((cb.checked) &amp;&amp; ~window.location.href.indexOf("?showpastdate")) { //Uncheck the checkbox and remove the "?showpastedate" from the url document.getElementById("showpastdate").checked = false; window.location.href.replace("?showpastdate",""); } else { // Else, check the checkbox and add the "?showpastedate" to the url document.getElementById("showpastdate").checked = true; window.location.href += "?showpastdate"; } </code></pre> <p>Note the use of the "~" in front of the <code>indexOf</code>.<br> If <code>string.indexOf("text")</code> finds <code>"text"</code> at the beginning of a string, like it would in <code>"tekstbooks bla bla bla"</code>, it returns 0. First index, starting count at 0.</p> <p>This zero is interpreted as a <code>false</code>, when implicitly casting it to a boolean. So, if the <code>indexOf</code> were to find a result at the first index, it should (In this situation) return <code>true</code> to indicate a string has been found. That's why we apply the <a href="http://www.javascriptturnsmeon.com/the-tilde-operator-in-javascript/" rel="nofollow">Bitwise NOT</a> <code>~</code> to the results of <code>indexOf</code>. <code>-1</code>, <code>indexOf</code>'s "Not found" value returns false, and all other results return true.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload