[SOLVED]Javascript and php help
Moderator: General Moderators
I usually write my javascript seperately and use php to do a script src=js page.
If I really need php to write my javascript I still write the javascript seperately first just to make sure it is working correctly then I very, very carefully put my php code and tags and \" and other such niceties into my js code.
It can be a bit of a headache but you will get there, just keep things simple first then work up from there.
phpScott
If I really need php to write my javascript I still write the javascript seperately first just to make sure it is working correctly then I very, very carefully put my php code and tags and \" and other such niceties into my js code.
It can be a bit of a headache but you will get there, just keep things simple first then work up from there.
phpScott
Javascript error
Hi,
I am still having trouble with javascript
Here's my code where i am trying to open an image in a new window..
I am getting an error saying "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' "
Can somebody please help me with this error.. I tried to find it but couldnt...
The error is on that link.
Thanks
I am still having trouble with javascript
Here's my code where i am trying to open an image in a new window..
Code: Select all
<?php
<script>
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
echo '<a href="javascript:;" onClick="MM_openBrWindow('"/images/products/royal/".$row['itemURL'].".jpg"','','"width="".$row['itemWidthLarge']. "",height="".$row['itemHeightLarge']."""')">';
?>Can somebody please help me with this error.. I tried to find it but couldnt...
The error is on that link.
Thanks
Javascript pop-up window help
Hi..
I was using the Javascript code by phpScott and it sort of works... now it opens a new window, but it does not load the image... at the end of the url it says 'undefined' ex. http://www.xyz/image/undefined
I kinda changed phpScott's code to suite my style...
This is the function that I used from Scott's
Can someone please tell me why it says undefined, instead of getting part of the image name from 'itemURL'?
I was using the Javascript code by phpScott and it sort of works... now it opens a new window, but it does not load the image... at the end of the url it says 'undefined' ex. http://www.xyz/image/undefined
I kinda changed phpScott's code to suite my style...
This is the function that I used from Scott's
Code: Select all
function displayLargeImage(nme)
{
url="./images/products/royal/"+nme+".jpg/";
window.open(url, nme)
}Code: Select all
$x.="<a href="javaScript:displayLargeImage(".$results[$row]['itemURL'].")">\n";
echo $x;- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
2nd last message - you have a single quote in there that needs escaping.
last message - you may need to add single quotes around the image url you are adding. I'm not a wiz at js - I've been spending a while catching up after leaving it in the dust a few years back but a few changes will also help in the function I think - try declaring the url variable first:
In your actual link from PHP:
Adding those extra single quotes just might do the trick...
last message - you may need to add single quotes around the image url you are adding. I'm not a wiz at js - I've been spending a while catching up after leaving it in the dust a few years back but a few changes will also help in the function I think - try declaring the url variable first:
Code: Select all
<?php
function displayLargeImage(nme)
{
var url;
url = "./images/products/royal/" + nme + ".jpg/";
window.open(url, nme);
}
?>Code: Select all
<?php
$x.="<a href="javaScript:displayLargeImage('".$results[$row]['itemURL']."')">\n";
?>this function here is just a little wrong, probably my fault try this.
the window.open synatax requires at least the url of the window you are opening and a proper window name. You can do all sorts of other stuff, just look it up on the web. the window name needs to be quotes if it is not a js variable.
try alerting the url before you do the window.open to make sure it looks alright.
Code: Select all
function displayLargeImage(nme)
{
url="./images/products/royal/"+nme+".jpg/";
window.open(url, 'newPage')
}try alerting the url before you do the window.open to make sure it looks alright.
Javascript pop-up window help
This is frustrating... I cant believe Javascript can become this hard for me..
This pop-up window still doesnt work
I tried the second last help i received adding single quotes, but it takes me to an unrestricted page
The last post (phpScott).. didnt help.. its still giving me undefined.jpg
This is really getting on my nerves... is there any other way of doing this???
Also if this helps... when i look at the source of the thumbnail page... after every thumbnail javascript: displayLargeImage() repeats..
For example, on the first image the line is printed once
on the second thumbnail that line is repeated twice.. and so on
This pop-up window still doesnt work
I tried the second last help i received adding single quotes, but it takes me to an unrestricted page
The last post (phpScott).. didnt help.. its still giving me undefined.jpg
This is really getting on my nerves... is there any other way of doing this???
Also if this helps... when i look at the source of the thumbnail page... after every thumbnail javascript: displayLargeImage() repeats..
For example, on the first image the line is printed once
on the second thumbnail that line is repeated twice.. and so on
call this page somethink like showpic.php
then in you js that makes the new window do this.
Hopefully that will solve your problem
Code: Select all
<?php
if(isset($_GET['picName']))
{
$src="<img src="".$_GET['picName']."" alt="whatever you want">
}
else
{
$src="<img src="default.gif" alt="default pic">
}
?>?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php if(isset($src)) echo $src; ?>
</body>
</html>
?>Code: Select all
function displayLargeImage(nme)
{
url="./images/products/royal/showpic.php?picName="+nme+".jpg/";
window.open(url, 'newPage')
}Javascript pop-up window help
I am so sorry Scott.. u've been a great help... it still doesnt work..
Here's the link that i am working on, its not a perfect looking page...
http://www.shalemdistributors.com/web/g ... xample.php
Thanks
Here's the link that i am working on, its not a perfect looking page...
http://www.shalemdistributors.com/web/g ... xample.php
Thanks
Progress !!!!
Now I am somewhat happy..
I took the $result out in my <a href>.. i didnt need that because i have a while statement...
So now here's the next problem... it url points to the right address, but give me a page saying 'File not found'... does this have something to do with .jpg in the displayLargeImage() function in my js???
the link is in the previous post if anyone of you to see what I am trying to explain
I took the $result out in my <a href>.. i didnt need that because i have a while statement...
So now here's the next problem... it url points to the right address, but give me a page saying 'File not found'... does this have something to do with .jpg in the displayLargeImage() function in my js???
the link is in the previous post if anyone of you to see what I am trying to explain
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Rather than answer your specific problem I thought I'd just give you some hints for debugging Javascript.
1) Use a Firefox/Mozilla Browser and activate the Javascript Console (under Tools Menu).
2) When you have a problem combining PHP and Javascript save the document source (created with PHP) to a file and load it on it's own using the browser. Debugging the javascript on the page should allow you to see what is going wrong in your PHP, especially when it comes to quotes.
3) Where possible have a separate javascript file containing all the necessary functions and load it using HTML. This way only functions calls should need to be called from the PHP.
1) Use a Firefox/Mozilla Browser and activate the Javascript Console (under Tools Menu).
2) When you have a problem combining PHP and Javascript save the document source (created with PHP) to a file and load it on it's own using the browser. Debugging the javascript on the page should allow you to see what is going wrong in your PHP, especially when it comes to quotes.
3) Where possible have a separate javascript file containing all the necessary functions and load it using HTML. This way only functions calls should need to be called from the PHP.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Ok to answer your actual question...
does not exist. Nothing to do with Javascript.
Code: Select all
http://www.shalemdistributors.com/images/products/royal/imagePage.phpget rid of the final slashs in the javascript
and see if that works.
Code: Select all
function displayLargeImage(nme)
{
url="./images/products/royal/showpic.php?picName="+nme+".jpg";
window.open(url, 'newPage')
}Javascript and php help
Thanks to both of you (previous two post).. finally I can take a deep breath .. it works Javascript Rocks!!!
Thanks guys, you have been great and to everyone to tried to help me.
God Bless you all.
Thanks guys, you have been great and to everyone to tried to help me.
God Bless you all.