Send a javascript string

Asked

Viewed 34 times

0

Is there any way to send a string by parameters in javascript?

I have something like:

<i class="fa fa-folder-open" aria-hidden="true" style="cursor:pointer;" onclick="en('.$datas['contribuinte'].')"></i> 

This button when you click, you have to take the variable to the function, but sometimes the variable inside can contain zeros on the left, so the function recognizes as integer and takes out zeros, so I want to turn it into string.

Function:

    function en(x)
{
    window.open("en/vers.php?cls="+x,"_blank");
}

Example: If the variable contains "000000001" I didn’t want the function to turn into "1".

  • 1

    In this case you have to deal with it in PHP, that is to say make a string on the PHP side. It is the most correct.

1 answer

0


The best thing you can do and create logic in PHP. You can also do it in javascript.

To be able to do something like that.

if(is_numeric($datas['contribuinte'])) {
    $myvar = (int)$datas['contribuinte'];
} else {
    $myvar = $datas['contribuinte'];
}

And now on the front end

onclick="en('.$myvar.');"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.