stupid little syntax error - javascript and php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

stupid little syntax error - javascript and php

Post by John Cartwright »

can't seem to get this to work :S

Code: Select all

<?php ?>
<a href="javascript:window.open("picture.php?<? echo "type=$type&picture=$picture&title=$title"; ?>", "Picture Viewer","toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no");> <img src=" <? echo "portfolio/$type/$picture"; ?>" width="450" height="410" border="1"></a>
<? ?>
Is it a missing quote? what what what

lol ty.. sorry for this nub question just its making me so mad
Last edited by John Cartwright on Mon Mar 22, 2004 9:59 pm, edited 3 times in total.
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

for one thing you don't have a semicolin[;] at the end of your lines
Last edited by bawla on Mon Mar 22, 2004 10:00 pm, edited 2 times in total.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

you have to add a semicolon

Code: Select all

<? echo "type=$type&picture=$picture&title=$title"; ?> //here

<? echo "portfolio/$type/$picture"; ?> // and here
Edited: Damn, I'm not quick enough :x
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

When I run the code and I check the link of the image it is only returning this:

javascript:window.open(
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Does it work now???
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

no......... jus said it only returns

javascript:window.open(
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

from wut i know of javascript

Code: Select all

<a href="javascript:window.open("picture.php?<? echo "type=$type&picture=$picture&title=$title"; ?>", "Picture Viewer","toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no");>
has to be one line, please correct me if im wrong
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

instead of doing

Code: Select all

href="javascript:window.open...
try doing

Code: Select all

href="#" onclick="window.open...
.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

bawla wrote:from wut i know of javascript

Code: Select all

<a href="javascript:window.open("picture.php?<? echo "type=$type&picture=$picture&title=$title"; ?>", "Picture Viewer","toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no");>
has to be one line, please correct me if im wrong
It is 1 line... this textbox is just not large enough...

Andre: That isn't working either :S
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Are you getting a php error, or a javascript error?
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

i should have thought before i posted
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

andre_c wrote:Are you getting a php error, or a javascript error?
java..when the link is clicked
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

How about seperating each 'section' of that line into it's own variable and then echo the variables?

eg.

Code: Select all

<?php
$var1 = "<a href="";
$var2 = $varable_from_someplace;
$var3 = "" target="_top">clickme!</a>";
$display = $var1 . $var2 . $var3;
echo $display;
?>
It makes things a bit more simple, not to mention organized.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I don't think that would work.... from my experience I have never been able to input/output javascrjpt inside php.. I also had to escape it.. I wish it were as simple as setting the target to a new window :S
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

what does the error say? I would recommend trying one of these browser if you have one: Netscape, firefox, opera, or any that has a javascript console. That way you can get much more details on the errors.

... and sami is right, you can write javascript from php. I do it all the time. (you can't write php using javascript though, just making sure you know :wink:)
Last edited by andre_c on Mon Mar 22, 2004 10:21 pm, edited 1 time in total.
Post Reply