PHP:
<?php
$test = "100-12";
?>
jQuery:
var test = <?php echo $test ?>;
alert(test);
in dev tool sources (F12) it looks like this:
var test = 100-12;
but when already alerted / pass the data in other pages or just alerted the value of test becomes 89 which is the value when 100 is subtracted by 12.
i need the as is value which is 100-12 not the subtracted. how do i stop jQuery from subtracting my string.
i tried String() toString() and even "" + but nothing works.
If you want to preserve that (no arithmetic), wrap it with quotes.
So if:
<?php
$test = "101-12"; // if this is the origin value
?>
<script type="text/javascript">
var test = '<?php echo $test; ?>'; // just put quotes in here as well, so that it does not interpolate it as intergers and do arithmentic
alert(test);
</script>
var test = "101-12";
will do your job