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 8859345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:02:15+00:00 2026-06-14T15:02:15+00:00

Im totally new to javascript and i have no clue how to get this

  • 0

Im totally new to javascript and i have no clue how to get this to work… I modified the code a little, but note that line 6 makes no sense. That is the main reason for this post.

<script>
function checkReloading() {
    if (window.location.href.split=="?showpastdate") {
        document.getElementById("showpastdate").checked=true;
    } else {
        document.getElementById("showpastdate").checked=false;
    }
}

function toggleAutoRefresh(cb) {
    if (cb.checked) {
        window.location.replace("?showpastdate");
    } else {
        window.location.replace("");
    }
}
window.onload=checkReloading;
</script>

Ok i think this is pretty readable.

First of all window.location.href.split doesn’t work because I have to give in the full path. But how can I make this dynamic, so it can be used on more websites? Everywhere I see: window.location.protocol + "//" + window.location.host + "/" + window.location.pathname; but how do I implement this line of code for dynamic webpages? Can someone give me an example?

What I want to achieve with this code is:
When showpastdate is checked, href to ?showpastdate, when at ?showpastdate stay checked so i can use php $_GET on ?showpastdate. This works (when i use static full url). But than…

How do I have to modify this code so that the checkbox remains checked at ?showpastdate untill clicked again, than url goes back to original .php state or other GET var?

Sorry for asking for code writing, but I bet some of u can write this simple lines in 2 minutes while I’m surfing around for 8 hours. Not about to learn javascript, but this really would be a nice option for my program to toggle item showing past date ON/OFF, nicer than having 2 checkboxes, 1 for ON and 1 for OFF 😡 EDIT: + a submit button @(O _o)@

Thanx in advance.

  • 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-06-14T15:02:17+00:00Added an answer on June 14, 2026 at 3:02 pm

    Okay. I got it.

    <script>
    function toggleAutoRefresh(cb) {
        if (~window.location.href.indexOf("?hidepastdate") == 0){
            window.location.replace("?hidepastdate");
            document.getElementById("showpastdate").checked == true;
        }
        if (~window.location.href.indexOf("?showpastdate") == 0){
            window.location.replace("?showpastdate");
            document.getElementById("showpastdate").checked == true;
        }
    }
    </script>
    

    Now the URL gets toggled every time at clicking and PHP does the CSS display work.

    Thanks for the effort and for pointing me to the right direction, Cerbrus! Saved me alot of time.

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

Sidebar

Related Questions

Totally new to programming so kindly excuse the silly question. I have this URL
Totally new to Capistrano. I have a local git repository that I want to
I'm totally new to AWS. I managed to have an instance that runs PHPMyAdmin.
please give me some clue for this javascript problem. I have a global variable
I'm totally newbie in javascript/jQuery and i have a little problem :) I'm using
I have this school assignment that I've been working on and am totally stumped
Probably a dead simple and idiotic question (I'm totally new to javascript): I have
I am totally new to javascript and I have a very easy to answer
im totally new when it comes to trying to make HTML code. I was
I'm totally new to this WCF Services thing so any guidelines would be greatly

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.