Boby Boby - 2 years ago 73
PHP Question

Passing '&' and space javascript

Good day, sir. I'm trying to pass my JS variable to a PHP function. I don't know how to say it, my English is bad. Please check my script first,

My JS. I only know to change the space.

function names()
var dept=$('#dept').val();
dept=dept.trim().replace(/ /g, '-');
'<?php echo base_url();?>index.php/penilaian/list_dropdown/'+ dept,
{ dept:dept },

And my php script

function list_dropdown($deptcode)
$newdeptcode = str_replace("-"," ",$deptcode);
echo $newdeptcode;

When dept value has a space, like "A B", its working fine, but when dept value has an & like "A&C" I can't receive it. So, how i can replace "&" with my JS.

Answer Source

You should pass &amp; instead of & for the dept.

dept.replace(/&/g, '&amp;');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download