Jump to content

Javascript and GET values


ThePsion5

Recommended Posts

Hi,I'm trying to write a small function in javascript that creates a popup window and passes GET values into it. The GET values are already included via PHP code, but javascript doesn't seem to like this. I get an error message that reads the following:

Error: invalid assignment left-hand sideSource Code:popup(related.php?id=1&field=clients)-----------------------------^

Here's the code for the actual javascript function:

function popup(url){  related = window.open (url, "related",  "location=0,status=0,scrollbars=1, toolbar=0,  menubar=0, directories=0");}

and here's how I call the function in PHP:

$url = "related.php?id=$Client->clientID&field=$table";print "<td><a onclick=\"popup($url)\">$Client->numKeywords</a></td>";

I don't think I'm doing anything incorrectly, any idea as to what might be up? Thanks in advance!

Link to comment
Share on other sites

This opens a new window with javascript bassed on the url passed from php.

<head><script>function popup(url){ related = window.open (url, "related","location=1,status=0,scrollbars=1, toolbar=0, menubar=0, directories=0");}</script></head><body><?php ini_set ('display_errors', 1);error_reporting (E_ALL & ~E_NOTICE);$url = "related.php?id=$Client->clientID&field=$table";print '<table border="1"><tr><td><a onclick=\'popup("' .$url. '")\'>Click Me</a></td></tr></table>';?></body>

Does this solve your problem? :)

Link to comment
Share on other sites

Well I am not shure that JS generally allows for grabbing get or post values but you can use php and javascript together. :) For example

<?PHP $id = $_GET['id'];$field = $_GET['field'];?><script type="text/javascript">var wid =<? echo $id; ?>;var wfield =<? echo $field; ?>;</script>

It might not be perfect and it is lengthy, but last time I ran the code similiar to it I had no issues and could use my PHP set variables quite easily in my JS. There is probaly a more effective way, but this is the method of choice I use.

Link to comment
Share on other sites

If you really want to use JavaScript to get the query string values you might wanna take a look at this http://www.tek-tips.com/faqs.cfm?fid=5442

Well, I ended up not using GET values directly in the javascript, but I created two javascript functions that ended up doing what I needed much better anyway. I created one function to open the new window with the specified chrome (or lack thereof) and then created another javascript function executed at the bottom of the page that resized it appropriately. This makes more sense anyway since the size of the page depends on the number of results pulled from a database, so in order to avoid unneeded DB queries I would have had to pass an entire mysql result set through to the new window. And that isn't something I'm going to try and figure out right now. Thanks for the help, guys!-Sean
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...