Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript variable in a window.open function

Status
Not open for further replies.

robburne

Programmer
May 10, 2005
33
GB
Can anyone help with my javascript code please?

I have a button which when pressed calls a function named 'popjack' which pops up a new browser window. The function is called with a paramter 'printflag' and I want to assign the value of this to a variable 'var1' in the url of the browser window to be opened.

Here is my code below, but 'var1=' part is wrong, can anyone help please. Many thanks.

<script language="JavaScript">

function popjack(printflag){

window.open('myfile.php?var1=printflag','popjack1',
'toolbar=no,location=no,width=650,height=534');
}

</script>

<button class=button onClick="JavaScript: popjack(1)"> Print Waybill</button>
 
Take a look at this:

Code:
<script>
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
function displayItem(key){
if(queryString(key)=='false') 
{
document.write("you didn't enter a ?name=value querystring item.");
}else{
document.write(queryString(key));
}
}
</script>

<body onload="displayItem('name');">
 
Hi, thanks for the reply, I can't see the answerin that code. It has to be simpler than that doesn't it?

Rob.
 
Hmm try this:

window.open("myfile.php?var1='printflag'",'popjack1',
'toolbar=no,location=no,width=650,height=534');
 

This should work for you:

Code:
function popjack(printflag) {
	window.open('myfile.php?var1=' + escape(printflag), 'popjack1', 'width=650,height=534');
}

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks for the reply, but it doesn't work , I am getting a message saying errors on page.

Rob.
 

Really? What are the errors you are getting with the code I just gave?

What browser are you trying this in?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Billy,

Hi my reply stating it didn't work was in response to bclt's post, I will try your offering now and report back.

Rob.
 
Works perfectly Peter, thanks very much I have been agonising over this for a day or two.

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top