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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotes Are Difficult

Status
Not open for further replies.

Louth

Programmer
Jan 21, 2004
16
EU
Could somebody please tell me how I could solve the following problem. I have created some JavaScript to create a pop-up window which looks like this:

<script language='javascript'>

var popWin = null
var winCount = 0
var winName = 'popWin'

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
var d_winLeft = 20
var d_winTop = 20
winName = 'popWin' + winCount++
closePopWin()
if (openPopWin.arguments.length >= 4)
winFeatures = ',' + winFeatures
else
winFeatures = ''
if (openPopWin.arguments.length == 6)
winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
else
winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
popWin = window.open(winURL, winName, 'width=' + winWidth
+ ',height=' + winHeight + winFeatures)
}
function closePopWin(){
if (navigator.appName != 'Microsoft Internet Explorer'
|| parseInt(navigator.appVersion) >=4)
if(popWin != null) if(!popWin.closed) popWin.close()
}
function getLocation(winWidth, winHeight, winLeft, winTop){
return ''
}

function getLocation(winWidth, winHeight, winLeft, winTop){
var winLocation = ''
if (winLeft < 0)
winLeft = screen.width - winWidth + winLeft
if (winTop < 0)
winTop = screen.height - winHeight + winTop
if (winTop == 'cen')
winTop = (screen.height - winHeight)/2 - 20
if (winLeft == 'cen')
winLeft = (screen.width - winWidth)/2
if (winLeft>0 & winTop>0)
winLocation = ',screenX=' + winLeft + ',left=' + winLeft
+ ',screenY=' + winTop + ',top=' + winTop
else
winLocation = ''
return winLocation
}

</script>

In the body I have created a link as follows:

<a href='JavaScript:eek:penPopWin("access.php?page=experience_add&count=$count&alumni_id=$alumni_id", 300, 300, "", "", "")'>Add More</a>

However because of the double quotes I have to jump out of PHP and then I can't access the variables $count and $alumni_id. Is there a way around this?
 
PHP has two string delineators -- single quote and double quote. Generally, if your output requires inclusion of the doublequote character, you should enclose the string in single quotes.


As an aside, "pain in the ass" is an unprofessional inclusion in a thread title.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I know single quotes are used instead of double quotes in PHP. I have tried to use single quotes instead. It seems to be JavaScript that has a problem with them though. Besides if I try to use single quotes the link just stops after the end of the first single quote pair and doesn't include the rest of the URL. Do you know of any other way I could get around this?
 
Is this a quoting problem with JavaScript, or a quoting problem with PHP outputting JavaScript.

If it's the latter, your question is more appropriate to the JavaScript forum. If it is the latter, then I'd have to see your print or echo statement.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It's OK I just figured out the problem. I had spaces after the commas in the URL. I had a feeling it was something simple. Always is. Cheers for the help anyway.
 
If spaces are causing the problem, then your quoting still isn't quite right.
Netscape 4.x will have problems with spaces in the "parameters" attribute of a window.open. Internet Explorer, on the other hand (being far less pedantic) doesn't care!

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Most browsers are space-sensitive. They have to be, due to the nature of HTML.

Given the following HTML:

Code:
<html>
   <body>
      <a href="show_get.php?a=the end">click</a><br>
      <a href=show_get.php?a=the_end>click</a><br>
      <a href=show_get.php?a=the end>click</a>
   </body>
</html>

Clicking on the first link sets $_GET['a] to 'the end'.
Clicking on the second link sets $_GET['a] to 'the_end'.
Clicking on the third link sets $_GET['a] to 'the'.

This is true for IE, Mozilla, and Opera.

If spaces are causing problems, then then quotes around attribute values are not correct.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
In HTML yes. But in JavaScript it is not always the case! Try the following example:
Code:
window.open("[URL unfurl="true"]http://www.google.com",[/URL] "google", "height=100, width=100, scrollbars=yes, resizable=yes, status=yes");

In IE and Netscape 7 it will open (assuming you don't have popup's blocked) a window 100 by 100, resizable, with scrollbars, and a status bar.

In NS4.7x you will open a window the same size as the Opener, with no scrollbars, no status bar, and it won't be resizable.

Replace the code with:
Code:
window.open("[URL unfurl="true"]http://www.google.com",[/URL] "google", "height=100,width=100,scrollbars=yes,resizable=yes,status=yes");
And all works as expected (in all browsers).

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
The problem in this thread, however, takes place in the "href" attribute of an <A> tag:

<a href='JavaScript:eek:penPopWin("access.php?page=experience_add&count=$count&alumni_id=$alumni_id", 300, 300, "", "", "")'>Add More</a>

Thus, an HTML attribute quoting problem.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top