SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Fail to convert data type of php variable

    I am trying to show alert message and message is defined in php valiable. My script is:


    ----------------------------------------------------------------------
    <body onLoad="data()">

    <?
    $txt="287331232138911111212323";
    echo gettype($txt); // returing string

    ?>

    <script language="javascript">

    function data()

    {
    message = new String;
    message=<?php echo $txt;?>+" ";
    alert(message);

    document.getElementById('myframe').contentWindow.document.body.innerHTML =message;


    }

    </script>

    <iframe id="myframe" src="images/blank.html"></iframe>
    </body>

    ------------------------------------------------------------------

    It shows me "2.8733123213891113e+23" instead of "287331232138911111212323" as alert message. I can't understand why it bocomes integer even type casting has been implemented. If I set any cahracter value in $text variable then it does not show any message.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just write it like this?
    Code:
    message = "<?php echo $txt; ?>";
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. Thanks a lot. I just over look this silly thing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •