How to pass an integer value to JS that is in a PHP integer variable?












0















I'm trying to pass some variables from PHP to JS.



I saw here that for strings the following code would work:



    var str = "<?php echo $x; ?>";


I've been using this:



    var var1 = <?= $var1 ?>;


Which one should I use for int? the first version is always good? Is the second one just an old form? I'd be happy for a clarification and instruction on passing variables (dif types) from php to js in general.



Thanks!










share|improve this question

























  • If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

    – epascarello
    Jan 8 '12 at 5:48











  • The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

    – Jared Farrish
    Jan 8 '12 at 5:50








  • 1





    This question has been asked so many times. The best and safest way to do it is json_encode.

    – igorw
    Jan 8 '12 at 13:32
















0















I'm trying to pass some variables from PHP to JS.



I saw here that for strings the following code would work:



    var str = "<?php echo $x; ?>";


I've been using this:



    var var1 = <?= $var1 ?>;


Which one should I use for int? the first version is always good? Is the second one just an old form? I'd be happy for a clarification and instruction on passing variables (dif types) from php to js in general.



Thanks!










share|improve this question

























  • If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

    – epascarello
    Jan 8 '12 at 5:48











  • The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

    – Jared Farrish
    Jan 8 '12 at 5:50








  • 1





    This question has been asked so many times. The best and safest way to do it is json_encode.

    – igorw
    Jan 8 '12 at 13:32














0












0








0








I'm trying to pass some variables from PHP to JS.



I saw here that for strings the following code would work:



    var str = "<?php echo $x; ?>";


I've been using this:



    var var1 = <?= $var1 ?>;


Which one should I use for int? the first version is always good? Is the second one just an old form? I'd be happy for a clarification and instruction on passing variables (dif types) from php to js in general.



Thanks!










share|improve this question
















I'm trying to pass some variables from PHP to JS.



I saw here that for strings the following code would work:



    var str = "<?php echo $x; ?>";


I've been using this:



    var var1 = <?= $var1 ?>;


Which one should I use for int? the first version is always good? Is the second one just an old form? I'd be happy for a clarification and instruction on passing variables (dif types) from php to js in general.



Thanks!







php javascript variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:19









Community

11




11










asked Jan 8 '12 at 5:45









Lucy WeatherfordLucy Weatherford

2,039124070




2,039124070













  • If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

    – epascarello
    Jan 8 '12 at 5:48











  • The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

    – Jared Farrish
    Jan 8 '12 at 5:50








  • 1





    This question has been asked so many times. The best and safest way to do it is json_encode.

    – igorw
    Jan 8 '12 at 13:32



















  • If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

    – epascarello
    Jan 8 '12 at 5:48











  • The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

    – Jared Farrish
    Jan 8 '12 at 5:50








  • 1





    This question has been asked so many times. The best and safest way to do it is json_encode.

    – igorw
    Jan 8 '12 at 13:32

















If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

– epascarello
Jan 8 '12 at 5:48





If it is in int, than you would not want the quotes, so you would remove them in the first code sample.

– epascarello
Jan 8 '12 at 5:48













The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

– Jared Farrish
Jan 8 '12 at 5:50







The second uses shorttags syntax, which is suggested not to be used by some (and there have been rumblings that PHP will drop default shorttag syntax being enabled at some point in the future, and some setups don't have it enabled, etc.).

– Jared Farrish
Jan 8 '12 at 5:50






1




1





This question has been asked so many times. The best and safest way to do it is json_encode.

– igorw
Jan 8 '12 at 13:32





This question has been asked so many times. The best and safest way to do it is json_encode.

– igorw
Jan 8 '12 at 13:32












6 Answers
6






active

oldest

votes


















6














First of all, lets go over how to declare a variable in javascript.



There are many types of variables, but lets go over int and string. Strings have to have quotation marks around the. Int's don't.



var int = 5;
var string = "hello";


Now when we are passing a variable from php to javascript, all we are doing is replacing the value after the equal sign with a variable declared in php. You mentioned the two ways for echoing a variable.



var str = "<?php echo $phpVariable; ?>";
var str = "<?= $phpVariable ?>";


If these variables were int (which by the way includes any number, whether integer or not), there would be no quotation marks around the php open and close tags. Now, you said you prefer using the second method. I would really advise you not to. Even though it is a lot easier to type <?= $phpVariable ?> than <?php echo $phpVariable; ?>, the former one isn't supported on all servers, whereas the latter one is. You can use it if you want, but if you ever want to move to a server, you need to check if that syntex is allowed first.






share|improve this answer



















  • 1





    thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

    – Lucy Weatherford
    Jan 8 '12 at 6:08






  • 1





    @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

    – blake305
    Jan 8 '12 at 6:09











  • Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

    – Lucy Weatherford
    Jan 8 '12 at 6:09



















2














Well,
Lets say in PHP,



$php_int_variable = 5;
$php_string_variable = "Hello";


For getting it in javascript as like following,



var int = 5;
var string = "Hello";


You have to write,



var int = <?php echo $php_int_variable; ?>;
var string = "<?php echo $php_string_variable; ?> ";





share|improve this answer































    0














    For a general solution, use this:



    var data = JSON.parse("<?php echo addslashes(json_encode($data)); ?>");





    share|improve this answer



















    • 3





      There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

      – Ignacio Vazquez-Abrams
      Jan 8 '12 at 5:48













    • Oh dear lord. (And note, that's not my downvote.)

      – Jared Farrish
      Jan 8 '12 at 5:49





















    0














    EVEN Anyone with problems , make the Next Way !



    var str = "<?php echo $x; ?>"; 


    this to string !



    and



    var int = parseInt('<?php echo $x; ?>');


    this to Int!






    share|improve this answer































      0














      var a = parseInt("10") + "<br>";
      var b = parseInt("10.00") + "<br>";
      var c = parseInt("10.33") + "<br>";
      var d = parseInt("34 45 66") + "<br>";
      var e = parseInt(" 60 ") + "<br>";
      var f = parseInt("40 years") + "<br>";
      var g = parseInt("He was 40") + "<br>";

      var h = parseInt("10", 10)+ "<br>";
      var i = parseInt("010")+ "<br>";
      var j = parseInt("10", 8)+ "<br>";
      var k = parseInt("0x10")+ "<br>";
      var l = parseInt("10", 16)+ "<br>";

      var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;





      share|improve this answer


























      • WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

        – Sheng Slogar
        Nov 13 '18 at 18:24



















      -1














      The two versions are equivalent. The 2nd version is enabled when the short_open_tag option is enabled in your php.ini. In php 5.4, the <?= will be available even without short_open_tag enabled.






      share|improve this answer
























      • This was downvoted because it was too right?

        – gview
        Jan 8 '12 at 6:44











      • The first has quotes around the value and the second does not.

        – igorw
        Jan 8 '12 at 13:31











      • What are you talking about?

        – gview
        Jan 8 '12 at 19:39











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8775680%2fhow-to-pass-an-integer-value-to-js-that-is-in-a-php-integer-variable%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      First of all, lets go over how to declare a variable in javascript.



      There are many types of variables, but lets go over int and string. Strings have to have quotation marks around the. Int's don't.



      var int = 5;
      var string = "hello";


      Now when we are passing a variable from php to javascript, all we are doing is replacing the value after the equal sign with a variable declared in php. You mentioned the two ways for echoing a variable.



      var str = "<?php echo $phpVariable; ?>";
      var str = "<?= $phpVariable ?>";


      If these variables were int (which by the way includes any number, whether integer or not), there would be no quotation marks around the php open and close tags. Now, you said you prefer using the second method. I would really advise you not to. Even though it is a lot easier to type <?= $phpVariable ?> than <?php echo $phpVariable; ?>, the former one isn't supported on all servers, whereas the latter one is. You can use it if you want, but if you ever want to move to a server, you need to check if that syntex is allowed first.






      share|improve this answer



















      • 1





        thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

        – Lucy Weatherford
        Jan 8 '12 at 6:08






      • 1





        @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

        – blake305
        Jan 8 '12 at 6:09











      • Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

        – Lucy Weatherford
        Jan 8 '12 at 6:09
















      6














      First of all, lets go over how to declare a variable in javascript.



      There are many types of variables, but lets go over int and string. Strings have to have quotation marks around the. Int's don't.



      var int = 5;
      var string = "hello";


      Now when we are passing a variable from php to javascript, all we are doing is replacing the value after the equal sign with a variable declared in php. You mentioned the two ways for echoing a variable.



      var str = "<?php echo $phpVariable; ?>";
      var str = "<?= $phpVariable ?>";


      If these variables were int (which by the way includes any number, whether integer or not), there would be no quotation marks around the php open and close tags. Now, you said you prefer using the second method. I would really advise you not to. Even though it is a lot easier to type <?= $phpVariable ?> than <?php echo $phpVariable; ?>, the former one isn't supported on all servers, whereas the latter one is. You can use it if you want, but if you ever want to move to a server, you need to check if that syntex is allowed first.






      share|improve this answer



















      • 1





        thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

        – Lucy Weatherford
        Jan 8 '12 at 6:08






      • 1





        @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

        – blake305
        Jan 8 '12 at 6:09











      • Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

        – Lucy Weatherford
        Jan 8 '12 at 6:09














      6












      6








      6







      First of all, lets go over how to declare a variable in javascript.



      There are many types of variables, but lets go over int and string. Strings have to have quotation marks around the. Int's don't.



      var int = 5;
      var string = "hello";


      Now when we are passing a variable from php to javascript, all we are doing is replacing the value after the equal sign with a variable declared in php. You mentioned the two ways for echoing a variable.



      var str = "<?php echo $phpVariable; ?>";
      var str = "<?= $phpVariable ?>";


      If these variables were int (which by the way includes any number, whether integer or not), there would be no quotation marks around the php open and close tags. Now, you said you prefer using the second method. I would really advise you not to. Even though it is a lot easier to type <?= $phpVariable ?> than <?php echo $phpVariable; ?>, the former one isn't supported on all servers, whereas the latter one is. You can use it if you want, but if you ever want to move to a server, you need to check if that syntex is allowed first.






      share|improve this answer













      First of all, lets go over how to declare a variable in javascript.



      There are many types of variables, but lets go over int and string. Strings have to have quotation marks around the. Int's don't.



      var int = 5;
      var string = "hello";


      Now when we are passing a variable from php to javascript, all we are doing is replacing the value after the equal sign with a variable declared in php. You mentioned the two ways for echoing a variable.



      var str = "<?php echo $phpVariable; ?>";
      var str = "<?= $phpVariable ?>";


      If these variables were int (which by the way includes any number, whether integer or not), there would be no quotation marks around the php open and close tags. Now, you said you prefer using the second method. I would really advise you not to. Even though it is a lot easier to type <?= $phpVariable ?> than <?php echo $phpVariable; ?>, the former one isn't supported on all servers, whereas the latter one is. You can use it if you want, but if you ever want to move to a server, you need to check if that syntex is allowed first.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 8 '12 at 5:59









      blake305blake305

      1,72121949




      1,72121949








      • 1





        thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

        – Lucy Weatherford
        Jan 8 '12 at 6:08






      • 1





        @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

        – blake305
        Jan 8 '12 at 6:09











      • Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

        – Lucy Weatherford
        Jan 8 '12 at 6:09














      • 1





        thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

        – Lucy Weatherford
        Jan 8 '12 at 6:08






      • 1





        @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

        – blake305
        Jan 8 '12 at 6:09











      • Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

        – Lucy Weatherford
        Jan 8 '12 at 6:09








      1




      1





      thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

      – Lucy Weatherford
      Jan 8 '12 at 6:08





      thanks! this clears up things. Until now I did use only numbers, now I have the first string, and noticed the difference in syntax too.

      – Lucy Weatherford
      Jan 8 '12 at 6:08




      1




      1





      @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

      – blake305
      Jan 8 '12 at 6:09





      @LucyWeatherford Glad I could help. Please click the checkmark to the left of this post.

      – blake305
      Jan 8 '12 at 6:09













      Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

      – Lucy Weatherford
      Jan 8 '12 at 6:09





      Also, my text editor has an issue with the ; in the end of each of these lines. Any idea why? he says error message - unexpected `';" type - syntax error

      – Lucy Weatherford
      Jan 8 '12 at 6:09













      2














      Well,
      Lets say in PHP,



      $php_int_variable = 5;
      $php_string_variable = "Hello";


      For getting it in javascript as like following,



      var int = 5;
      var string = "Hello";


      You have to write,



      var int = <?php echo $php_int_variable; ?>;
      var string = "<?php echo $php_string_variable; ?> ";





      share|improve this answer




























        2














        Well,
        Lets say in PHP,



        $php_int_variable = 5;
        $php_string_variable = "Hello";


        For getting it in javascript as like following,



        var int = 5;
        var string = "Hello";


        You have to write,



        var int = <?php echo $php_int_variable; ?>;
        var string = "<?php echo $php_string_variable; ?> ";





        share|improve this answer


























          2












          2








          2







          Well,
          Lets say in PHP,



          $php_int_variable = 5;
          $php_string_variable = "Hello";


          For getting it in javascript as like following,



          var int = 5;
          var string = "Hello";


          You have to write,



          var int = <?php echo $php_int_variable; ?>;
          var string = "<?php echo $php_string_variable; ?> ";





          share|improve this answer













          Well,
          Lets say in PHP,



          $php_int_variable = 5;
          $php_string_variable = "Hello";


          For getting it in javascript as like following,



          var int = 5;
          var string = "Hello";


          You have to write,



          var int = <?php echo $php_int_variable; ?>;
          var string = "<?php echo $php_string_variable; ?> ";






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 8 '12 at 7:30









          Nuhil MehdyNuhil Mehdy

          1,23811316




          1,23811316























              0














              For a general solution, use this:



              var data = JSON.parse("<?php echo addslashes(json_encode($data)); ?>");





              share|improve this answer



















              • 3





                There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

                – Ignacio Vazquez-Abrams
                Jan 8 '12 at 5:48













              • Oh dear lord. (And note, that's not my downvote.)

                – Jared Farrish
                Jan 8 '12 at 5:49


















              0














              For a general solution, use this:



              var data = JSON.parse("<?php echo addslashes(json_encode($data)); ?>");





              share|improve this answer



















              • 3





                There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

                – Ignacio Vazquez-Abrams
                Jan 8 '12 at 5:48













              • Oh dear lord. (And note, that's not my downvote.)

                – Jared Farrish
                Jan 8 '12 at 5:49
















              0












              0








              0







              For a general solution, use this:



              var data = JSON.parse("<?php echo addslashes(json_encode($data)); ?>");





              share|improve this answer













              For a general solution, use this:



              var data = JSON.parse("<?php echo addslashes(json_encode($data)); ?>");






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 8 '12 at 5:48









              Niet the Dark AbsolNiet the Dark Absol

              257k53360468




              257k53360468








              • 3





                There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

                – Ignacio Vazquez-Abrams
                Jan 8 '12 at 5:48













              • Oh dear lord. (And note, that's not my downvote.)

                – Jared Farrish
                Jan 8 '12 at 5:49
















              • 3





                There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

                – Ignacio Vazquez-Abrams
                Jan 8 '12 at 5:48













              • Oh dear lord. (And note, that's not my downvote.)

                – Jared Farrish
                Jan 8 '12 at 5:49










              3




              3





              There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

              – Ignacio Vazquez-Abrams
              Jan 8 '12 at 5:48







              There's no need for JSON.parse() or addslashes() since all JSON values are by definition valid JavaScript literals.

              – Ignacio Vazquez-Abrams
              Jan 8 '12 at 5:48















              Oh dear lord. (And note, that's not my downvote.)

              – Jared Farrish
              Jan 8 '12 at 5:49







              Oh dear lord. (And note, that's not my downvote.)

              – Jared Farrish
              Jan 8 '12 at 5:49













              0














              EVEN Anyone with problems , make the Next Way !



              var str = "<?php echo $x; ?>"; 


              this to string !



              and



              var int = parseInt('<?php echo $x; ?>');


              this to Int!






              share|improve this answer




























                0














                EVEN Anyone with problems , make the Next Way !



                var str = "<?php echo $x; ?>"; 


                this to string !



                and



                var int = parseInt('<?php echo $x; ?>');


                this to Int!






                share|improve this answer


























                  0












                  0








                  0







                  EVEN Anyone with problems , make the Next Way !



                  var str = "<?php echo $x; ?>"; 


                  this to string !



                  and



                  var int = parseInt('<?php echo $x; ?>');


                  this to Int!






                  share|improve this answer













                  EVEN Anyone with problems , make the Next Way !



                  var str = "<?php echo $x; ?>"; 


                  this to string !



                  and



                  var int = parseInt('<?php echo $x; ?>');


                  this to Int!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 23 '15 at 2:53









                  Alisom MartinsAlisom Martins

                  379311




                  379311























                      0














                      var a = parseInt("10") + "<br>";
                      var b = parseInt("10.00") + "<br>";
                      var c = parseInt("10.33") + "<br>";
                      var d = parseInt("34 45 66") + "<br>";
                      var e = parseInt(" 60 ") + "<br>";
                      var f = parseInt("40 years") + "<br>";
                      var g = parseInt("He was 40") + "<br>";

                      var h = parseInt("10", 10)+ "<br>";
                      var i = parseInt("010")+ "<br>";
                      var j = parseInt("10", 8)+ "<br>";
                      var k = parseInt("0x10")+ "<br>";
                      var l = parseInt("10", 16)+ "<br>";

                      var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;





                      share|improve this answer


























                      • WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                        – Sheng Slogar
                        Nov 13 '18 at 18:24
















                      0














                      var a = parseInt("10") + "<br>";
                      var b = parseInt("10.00") + "<br>";
                      var c = parseInt("10.33") + "<br>";
                      var d = parseInt("34 45 66") + "<br>";
                      var e = parseInt(" 60 ") + "<br>";
                      var f = parseInt("40 years") + "<br>";
                      var g = parseInt("He was 40") + "<br>";

                      var h = parseInt("10", 10)+ "<br>";
                      var i = parseInt("010")+ "<br>";
                      var j = parseInt("10", 8)+ "<br>";
                      var k = parseInt("0x10")+ "<br>";
                      var l = parseInt("10", 16)+ "<br>";

                      var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;





                      share|improve this answer


























                      • WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                        – Sheng Slogar
                        Nov 13 '18 at 18:24














                      0












                      0








                      0







                      var a = parseInt("10") + "<br>";
                      var b = parseInt("10.00") + "<br>";
                      var c = parseInt("10.33") + "<br>";
                      var d = parseInt("34 45 66") + "<br>";
                      var e = parseInt(" 60 ") + "<br>";
                      var f = parseInt("40 years") + "<br>";
                      var g = parseInt("He was 40") + "<br>";

                      var h = parseInt("10", 10)+ "<br>";
                      var i = parseInt("010")+ "<br>";
                      var j = parseInt("10", 8)+ "<br>";
                      var k = parseInt("0x10")+ "<br>";
                      var l = parseInt("10", 16)+ "<br>";

                      var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;





                      share|improve this answer















                      var a = parseInt("10") + "<br>";
                      var b = parseInt("10.00") + "<br>";
                      var c = parseInt("10.33") + "<br>";
                      var d = parseInt("34 45 66") + "<br>";
                      var e = parseInt(" 60 ") + "<br>";
                      var f = parseInt("40 years") + "<br>";
                      var g = parseInt("He was 40") + "<br>";

                      var h = parseInt("10", 10)+ "<br>";
                      var i = parseInt("010")+ "<br>";
                      var j = parseInt("10", 8)+ "<br>";
                      var k = parseInt("0x10")+ "<br>";
                      var l = parseInt("10", 16)+ "<br>";

                      var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 13 '18 at 18:06









                      YakovL

                      2,954102439




                      2,954102439










                      answered Nov 13 '18 at 16:32









                      AL MaMunAL MaMun

                      125




                      125













                      • WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                        – Sheng Slogar
                        Nov 13 '18 at 18:24



















                      • WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                        – Sheng Slogar
                        Nov 13 '18 at 18:24

















                      WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                      – Sheng Slogar
                      Nov 13 '18 at 18:24





                      WhAT? The original question is over five years old and has absolutely nothing to do with the answer you just posted. I'm guessing you made a mistake, and I'd suggest you remove this answer.

                      – Sheng Slogar
                      Nov 13 '18 at 18:24











                      -1














                      The two versions are equivalent. The 2nd version is enabled when the short_open_tag option is enabled in your php.ini. In php 5.4, the <?= will be available even without short_open_tag enabled.






                      share|improve this answer
























                      • This was downvoted because it was too right?

                        – gview
                        Jan 8 '12 at 6:44











                      • The first has quotes around the value and the second does not.

                        – igorw
                        Jan 8 '12 at 13:31











                      • What are you talking about?

                        – gview
                        Jan 8 '12 at 19:39
















                      -1














                      The two versions are equivalent. The 2nd version is enabled when the short_open_tag option is enabled in your php.ini. In php 5.4, the <?= will be available even without short_open_tag enabled.






                      share|improve this answer
























                      • This was downvoted because it was too right?

                        – gview
                        Jan 8 '12 at 6:44











                      • The first has quotes around the value and the second does not.

                        – igorw
                        Jan 8 '12 at 13:31











                      • What are you talking about?

                        – gview
                        Jan 8 '12 at 19:39














                      -1












                      -1








                      -1







                      The two versions are equivalent. The 2nd version is enabled when the short_open_tag option is enabled in your php.ini. In php 5.4, the <?= will be available even without short_open_tag enabled.






                      share|improve this answer













                      The two versions are equivalent. The 2nd version is enabled when the short_open_tag option is enabled in your php.ini. In php 5.4, the <?= will be available even without short_open_tag enabled.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 8 '12 at 5:55









                      gviewgview

                      11.1k22639




                      11.1k22639













                      • This was downvoted because it was too right?

                        – gview
                        Jan 8 '12 at 6:44











                      • The first has quotes around the value and the second does not.

                        – igorw
                        Jan 8 '12 at 13:31











                      • What are you talking about?

                        – gview
                        Jan 8 '12 at 19:39



















                      • This was downvoted because it was too right?

                        – gview
                        Jan 8 '12 at 6:44











                      • The first has quotes around the value and the second does not.

                        – igorw
                        Jan 8 '12 at 13:31











                      • What are you talking about?

                        – gview
                        Jan 8 '12 at 19:39

















                      This was downvoted because it was too right?

                      – gview
                      Jan 8 '12 at 6:44





                      This was downvoted because it was too right?

                      – gview
                      Jan 8 '12 at 6:44













                      The first has quotes around the value and the second does not.

                      – igorw
                      Jan 8 '12 at 13:31





                      The first has quotes around the value and the second does not.

                      – igorw
                      Jan 8 '12 at 13:31













                      What are you talking about?

                      – gview
                      Jan 8 '12 at 19:39





                      What are you talking about?

                      – gview
                      Jan 8 '12 at 19:39


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8775680%2fhow-to-pass-an-integer-value-to-js-that-is-in-a-php-integer-variable%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Full-time equivalent

                      Bicuculline

                      さくらももこ