Reputation: 1202
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.
<script>
function names()
{
var dept=$('#dept').val();
alert(dept);
dept=dept.trim().replace(/ /g, '-');
alert(dept);
$.post(
'<?php echo base_url();?>index.php/penilaian/list_dropdown/'+ dept,
{ dept:dept },
function(data){
$('#listnama').html(data);
}
);
}
</script>
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.
Upvotes: 2
Views: 94
Reputation: 85545
You should pass &
instead of &
for the dept.
dept.replace(/&/g, '&');
Upvotes: 4