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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:56:36+00:00 2026-05-27T21:56:36+00:00

Here is a very simple PHP page with one javascript function in it. I

  • 0

Here is a very simple PHP page with one javascript function in it. I am seeing the output differently. I am not able to understand why is it behaving that way.

In the code below, x echoes as 012012, but when I pass it into a javascript function and display it in an innerHTML, it displays differently as 5130 ??!!

Can anyone help ?

<?php
    $x= date("mY");
    echo $x;
?>
<html>
    <head>
        <script>
            function myfunc1(y)
            {
                div1 = document.getElementById("mydiv1")
                div1.innerHTML = y;
            }
        </script>
    </head>
    <body <?php echo "onload='myfunc1(".$x.")'>";?>
    <div id="mydiv1" style="background:#efefef;border:1px solid green;height:100px;width:100px;text-align:center">
    </div>
    </body>
</html>

HTML output

012012<html>
    <head>
        <script>
            function myfunc1(y)
            {
                div1 = document.getElementById("mydiv1")
                div1.innerHTML = y;
            }
        </script>
    </head>
    <body onload='myfunc1(012012)'>    <div id="mydiv1" style="background:#efefef;border:1px solid green;height:100px;width:100px;text-align:center">
    </div>
    </body>
</html>

HTML output (screenshot)
Screenshot

  • 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-27T21:56:37+00:00Added an answer on May 27, 2026 at 9:56 pm

    This is happening because 012012 is being treated as an int. But, since it starts with 0, JavaScript treats it as base 8 (octal), and therefore converts it to 5130.

    You need to wrap 012012 in quotes, so JavaScript treats it as a string. Also, I suggest only using PHP to echo the value you need, not the entire function call. Makes it slightly easier to debug.

    <body onload="myfunc1('<?php echo $x;?>')">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope I am not missing something very simple here. I have done a
Very confused here, trying out the yuicompressor on a simple javascript file. My js
This is a very simple function if one where to use an input tag,
Here's a very simple Prototype example. All it does is, on window load, an
Here's a very simple question. I have an SP that inserts a row into
My goal here is to create a very simple template language. At the moment,
I guess there will be a very simple answer to this. But here goes.
¿How would I do the operation described here , which is very simple from
i'm missing something fundamental here. i have a very simple custom class that draws
I am very new to Perl, so please bear with my simple question: Here

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.