0

I’m trying to pass a variable from a PHP array to a JavaScript function. In the PHP array I have:

echo '<a href="JavaScript:void(0);" onclick="manager(&#39;';echo $Company;echo'&#39;)">'.$Manager.'</td>

If I use the function,

<script type="text/jscript">
function manager(Value){
alert(Value);
}
</script>

The hyperlink gives me a message box with the correct company for each row, so the PHP part seems OK. Now I want to pass the Company to a page and return the result to a div. I’ve tried using,

<script type="text/jscript">
function manager() {
$.post('manager.php', { Company: var.Value},
function (output) {
$('#info2').html(output).show();
});
}
</script>

with some variations like “Company: this.Value” and “Company: (Value)” and another method like,

<script type="text/jscript">
function manager(Value){
$("#info2").load("manager.php?"+this.manager.Value);
}
</script>

If I put the company in manually like “$("#info2").load("manager.php?Company=ACME”);” it works so I know the manager.php page is OK. I’m pretty sure I just don’t know how to pass the variable though the function correctly. Any ideas? Thanks.

James
  • 110
  • 1
  • 2
  • 13
  • possible duplicate of [passing PHP objects to javascript](http://stackoverflow.com/questions/6351949/passing-php-objects-to-javascript) – Michal Brašna Feb 04 '14 at 14:21

1 Answers1

0
<script type="text/jscript">
function manager(Value){
    $("#info2").load("manager.php?"+Value).show();
}
</script>
Steve
  • 20,703
  • 5
  • 41
  • 67
  • Actually I just figured out it does work as long as the company does not have any spaces. – James Feb 04 '14 at 14:55