1
echo "function disp_player (playerID) {";
    echo "$.post('editor.php', {'idval': playerID});";

    echo "alert(playerID);";
    echo "alert(" . $playerlist[$_POST['idval']][0] . ");";

I'm writing a PHP script that is supposed to change text based on a selection made from a drop down.

The page can be viewed here - http://superonlinehockey.com/editor.php

The first alert works and the playerID is output. Setting $playerlist[$_POST['idval']][0] to a static value like $playerlist[770][0] also works. Using Firebug, I see that the value is added to post and, also using Firebug, it looks like the code all works. However, that second alert gives me an 'Undefined' when I would expect it ot be the same as the first alert.

Can anyone help me? Am I posting wrong? I'm new to jQuery so I'm not sure how this is supposed to work but, based on what I do know, I don't see anything wrong with my code.

1 Answer 1

3

try

echo '$.post(\'editor.php\', {\'idval\': playerID});';

its because in php between " $some will behave as variable

and

echo "alert('" . $playerlist[$_POST['idval']][0] . "');";

Codepad

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this but, unfortuantely, the same thing occurred - the $_POST['idval'] is still undefined. If you need more code from me to understand what is happening, I can provide it. This is my call to jQuery - echo "<script src=\"code.jquery.com/jquery-1.8.3.min.js\"></script>"; That is working for another script I run on the page, so I'm pretty sure it isn't my jQuery call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.