0

I'm trying to pass multiple values from PHP into my javascript function. The function is simple right now, just trying to show a popup with the values:

    <script type="text/javascript">
        function showMapsInfo(name, ctr) {
            alert('Info = '+name +' '+ctr);
        }//function showMapsInfo
    </script>

When I just pass in one value, name or ctr, it works fine. However when passing in two or more values no alert occurs. Is there a reason this isn't working? I'm guessing if this is impossible I'll have to use AJAX to get the job done?

Here is the relevant PHP code. I am making multiple forms on the page, every id is unique via a ctr. I read in the $maps_name from a database. This I can output to the screen fine, so no issue there.

echo('<button type="button" id="button'.$ctr.'" onClick="showMapsInfo('.$maps_name.', '.$ctr.');"><img src="img/maps_logo.gif"></button><br/>');
0

1 Answer 1

5

I'm guessing you just need to quote $maps_name and $ctr beforehand (since they're most likely strings:

echo('<button type="button" id="button'.$ctr.'" onClick="showMapsInfo(\''.str_replace("'", "\\'", $maps_name).'\', \''.str_replace("'", "\\'", $ctr).'\');"><img src="img/maps_logo.gif"></button><br/>');
1
  • Thanks for the help, would've caught that one! Commented Nov 5, 2010 at 16:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.