javascript, jQuery convert PHP string to number

Working with PHP data inside javascript.
Echo or passing a php number in javascript may turn it to be string instead of integer.
example:

<input type="text" onchange="math( '<?php echo '1';?>' )">

<script type="text/javascript">
  function math( number ){
	//here the number will be string
	//to be able to process the string as number, use parseInt
	var no = parseInt(number);
  }
</script>

By Keenlio, May 9, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


× 1 = nine

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>