PHP Values in JS function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

PHP Values in JS function

Post by Steveo31 »

Simple window open script:

Code: Select all

function addComment(num){
window.open('addcomment.php?ref=articles_comments&article=num','Add A Comment', 'width=500,height=360,resizeable=no');
}
That I call later like

Code: Select all

<a href="javascript:addComment(<?php echo $_GET['doc']; ?>);">Add A Comment</a>
Works well, but the page it opens has the following URL:

http://localhost/public/addcomment.php? ... rticle=num

Which isn't what I want. I need it to have the &article equal the value given to it by the $_GET['doc']. I tried combining PHP and Javascript in the original function, but it didn't work. Is there a way of allowing Javascript to get the GET variables? Better yet, how can I make this method work?

:)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

window.open('addcomment.php?ref=articles_comments&article='+num,'Add A Comment', 'width=500,height=360,resizeable=no');
fix old-new php highlighter
Last edited by feyd on Fri Jan 13, 2006 8:18 pm, edited 1 time in total.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

You rock.

:D
Post Reply