Passing a long string as a parameter from php to js

Hai folks,

php

$test="1324-110075-32222-11007-23423423-23432432-65462312-110017";

echo "<span onclick='expand_all(" . $test . ");'>All</span>";

js

function expand_all(visa_number){
  alert(visa_number);
}

alert output : -125407

whats wrong?

You are not passing a string to your Javascript function. The code that is produced is actually,

expand_all(1324-110075-32222-11007-23423423-23432432-65462312-110017);

When in fact it should be,

expand_all("1324-110075-32222-11007-23423423-23432432-65462312-110017");

You just need to make a small change to your PHP.

echo "<span onclick='expand_all(\"" . $test . "\");'>All</span>";
1 Like

works charm :smile:

Thanks buddy!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.