Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Function call after body.onload returns unwanted result

I have the following problem:

<body>
<script>
function myfunction(y) {
    alert(y);
    }

var x = "1";
myfunction(x);
</script>
</body>

This script gives me the desired result: 1 However, the script is executed in my code only with document.body.onload:

<body>
<script>
document.body.onload = function myfunction(y) {
    alert(y);
    }

var x = "1";
myfunction(x);
</script>
</body>

But in this case the result is not 1, but [object Event]. What do I have to do to get 1 as result?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm not sure if this is what you mean:

function myfunction(y) {
  alert(y);
}
document.body.onload = function() {
  var x = "1";
  myfunction(x);
}

Basically, if you set onload as you function which takes a parameter - the argument will be event itself, not the value you tried to provide to it

You can read more here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!