Jump to content

pass php variable as argument in javascript function?


xjasonx

Recommended Posts

Heres two parts of the code:

 

echo "<script language=\"javascript\">";
echo "function openIt(x,y)";
echo "{";
echo "window.open(\"nwindow.php?id=arguments[0]&title=arguments[1]\",\"newwindow\",config=\"height=500,width=400\")";
echo "}";
echo "</script>";

 

"<a href=\"\" onClick=\"openIt($id,$title) \">Code</a></td>";

 

Then I get this error: Error:

missing ) after argument list
Source File: http://scriptsforgames.com/final_fantasy/scripts.php
Line: 1, Column: 17
Source Code:
openIt(1,Fishing V.1) 

 

Please help. I've tryed to fix this for so long.

You need to surround the arguments with quotes, since they are strings. I'm assuming the string is part of an echo statement:

<?php
echo "<a href=\"\" onClick=\"openIt('$id','$title') \">Code</a></td>";
?>

 

Ken

Wow, that was simple. So that got rid of the error, but now when I open the new window, it displays the variables as arguments[1].

 

echo "window.open(\"nwindow.php?id=arguments[0]&title=arguments[1]\",\"newwindow\",config=\"height=500,width=400\")";

 

Thanks a lot for the help. I won't be able to reply until tomorrow because I'm about to go to work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.