Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
possible duplicate of passing PHP objects to javascript –  Michal Brašna Feb 4 at 14:21

1 Answer 1

up vote 0 down vote accepted
<script type="text/jscript">
function manager(Value){
    $("#info2").load("manager.php?"+Value).show();
}
</script>
share|improve this answer
    
Tried that, does not work with for some reason... –  James Feb 4 at 14:41
    
@James What errors do you get in the console? –  user574632 Feb 4 at 14:46
    
Actually I just figured out it does work as long as the company does not have any spaces. –  James Feb 4 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.