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

The Archive Base Latest Questions

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

My JavaScript knowledge is shallow, so I can’t figure this out after some significant

  • 0

My JavaScript knowledge is shallow, so I can’t figure this out after some significant Googling (and searching here, of course) so I hope that this will enlighten me as to the principle of what I’m doing wrong, as well as providing a solution.

I’m putting a toggle checkbox writing a boolean to the backend database to track whether a record should be saved to a user’s application ‘home page’. The PHP code runs fine, and the OnClick event fires off correctly when the user clicks on the checkbox…

EXCEPT.. it also fires off every time the page is loaded. Which means when you open the page, it toggles you to the opposite of what you had previously.

Here is the code that it’s firing off:

<form name="checkHomePage">
 <?php 
    echo "<input ";
    if (checkHomePage($_REQUEST['refnum']) == 1) {echo " checked='checked' ";}
    echo " onClick='<?php echo ".toggleHomePage($_REQUEST['refnum']).";?>'";
    echo " type='checkbox'>Show On My Home Page</input>";
 ?>
</form>

For the life of me, I can’t figure out why the onClick is being triggered whenever the page loads. There’s no JS downstream in the PHP functions, they’re also returning the correct values.

Other datapoints: I’m only allowed to use minimal JavaScript on this project, such as OnClick triggers. Also, we’re only using IE8 and 9 internally.

Thank you 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-05-23T16:00:47+00:00Added an answer on May 23, 2026 at 4:00 pm

    The problem here is that you are sending the browser your <?php echo code. Use this instead:

    <form name="checkHomePage">
     <?php 
        echo "<input ";
        if (checkHomePage($_REQUEST['refnum']) == 1) {echo " checked='checked' ";}
        echo " onClick='toggleHomePage(".$_REQUEST['refnum'].")'";
        echo " type='checkbox'>Show On My Home Page</input>";
     ?>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write this PHP code in JavaScript? I have no knowledge about
My knowledge about javascript is very low; thus, this is a simple question. I
I just want to increase my core javascript knowledge. Sometimes I see this statement
I have a very simple problem, but I just can't figure it out. My
I know that given enough time I'll figure this out, but it sure would
Simple question, really. I just don't have the knowledge to do this with JavaScript,
Consider: var something = { wtf: null, omg: null }; My JavaScript knowledge is
I have a fair knowledge about Javascript, I started with jQuery 1.4 a week
I am trying to get a better working knowledge of JavaScript. So, I have
How would you explain JavaScript closures to someone with a knowledge of the concepts

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.