I am trying to use the substring method inside JavaScript code which echoes some PHP variable but it does not work.
$('#tarif_public_total').val( <?php echo $_tarif_public; ?> * $('#tarif_public').val() )
u=$('#tarif_membre').val()* <?php echo $_tarif_membre; ?> + $('#tarif_public').val()* <?php echo $_tarif_public; ?>
uu=u.substring(0,6)
$('#total_total').val(uu)
What am I doing wrong here?
After using
parseInt()on all the instances ofval()(like Gert G suggested) you have to do:or:
Since you can’t use substring on numbers. You have to cast back to a string using
("" + var)Live demo of (“” + var)