Jump to content

pass php variable as argument in javascript function?


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.