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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:27:28+00:00 2026-06-13T11:27:28+00:00

Guys i have little problem with PHP to call Javascript function on load …

  • 0

Guys i have little problem with PHP to call Javascript function on load …
Idea is when page load i do little calculation with PHP stuff , so when i finish that all i
want is to write that down in same DOM element using javascript.
I will not show you PHP code for calculation as i am 100% sure it is alright.
This is the code i got so far , so can you just tell me whats wrong with it?

$test = 100;
echo "<script language=javascript> window.onload=UpdatePoints($test); </script>";

and Javascript function is simple

function UpdatePoints(Points) {
document.getElementById('PointsNumber').innerHTML = Points;
}

Thanks 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-13T11:27:29+00:00Added an answer on June 13, 2026 at 11:27 am

    Instead of calling the function UpdatePoints() in window.onload, you need to wrap the call in a function that gets assigned by reference to window.onload. Otherwise, you are calling the function, and assigning its return value to window.onload.

    // This function wraps UpdatePoints($test)
    // and is assigned as a reference to window.onload
    function load() {
      UpdatePoints(<?php echo $test; ?>);
    }
    echo "<script type='text/javascript'> window.onload=load; </script>";
    

    Note that the language attribute to the <script> tag is deprecated. Include a type=text/javascript attribute in its place (though text/javascript is genearlly the browser default)

    However, since the value of $test is created before the page loads and cannot change when the function is called, you might as well not bother passing it as a parameter, in which case you don’t need to wrap the function. Just remove the () to assign it as a reference.

    echo "<script type='text/javascript'> window.onload=UpdatePoints; </script>";
    
    function UpdatePoints() {
      // PHP write directly into the function since the value
      // can't change...  It's always going to be passed as what PHP assigns 
      // if you call it as UpdatePoints($test)
      var Points = $test;
      document.getElementById('PointsNumber').innerHTML = Points;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys i have a little problem when i submit my form the page gets
Guys i have a little problem, i tried to find some examples on GeoIP
Hey guys! I have this little problem: I have one ViewController which adds 2
Hey guys, I have a little problem with a simple ajax request. I can't
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
I have a little problem for you guys. I would like to do this:
maybe you guys can help me i have a little problem here: I have
hey guys, somehow i can't find the solution for my little problem. i have
Guys i have a little problem , huge for me , so that is
Hey guys I have a little issue here. I have a panel where I

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.