Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

javascript on the fly with php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

javascript on the fly with php

Postby Joan Garnet » Sat Aug 03, 2002 3:29 am

Hello everybody!
I've got a problem trying to create a javascript function "on the fly" with php.

The link that calls the function:###########

Code: Select all
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";

The function:###############################

Code: Select all
function funct_one (archivo,id,tabla){
   window.open("escucha.php?table="+tabla+"&opcion=escucha&archivo="+archivo+"&id_gral="+id,"vent_escucha","width=500, height=300");

}


I'll appreciate your help!
ThanX!
:)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Re: javascript on the fly with php

Postby WiZARD » Sat Aug 03, 2002 5:27 am

Joan Garnet wrote:Hello everybody!
I've got a problem trying to create a javascript function "on the fly" with php.

The link that calls the function:###########

Code: Select all
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";

The function:###############################

Code: Select all
function funct_one (archivo,id,tabla){
   window.open("escucha.php?table="+tabla+"&opcion=escucha&archivo="+archivo+"&id_gral="+id,"vent_escucha","width=500, height=300");

}


I'll appreciate your help!
ThanX!
:)

I'll be help you, but i think what you need try find youre mistake. Read carefuly your code. If this not helped try read next:
http://www.devshed.com/Server_Side/PHP/ ... page2.html
or
http://www.zend.com/zend/tut/using-strings.php
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Re: javascript on the fly with php

Postby Jay » Sat Aug 03, 2002 5:58 am

Joan Garnet wrote:Hello everybody!
I've got a problem trying to create a javascript function "on the fly" with php.

The link that calls the function:###########

Code: Select all
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";

The function:###############################

Code: Select all
function funct_one (archivo,id,tabla){
   window.open("escucha.php?table="+tabla+"&opcion=escucha&archivo="+archivo+"&id_gral="+id,"vent_escucha","width=500, height=300");

}


I'll appreciate your help!
ThanX!
:)

As WiZARD has mentioned, your problem lies with the way you are interpreting strings. Strings are enclosed by either a single quote, or double quote. This quote will be the delimiter, and the next occurence of the quote will mean the end of the string.

Your link, when output, will read
Code: Select all
<a href='javascript:funct_one('previewValue','idValue','table1Value')'>click here</a>


Can you see the error? You have enclosed your href command with single quotes, and also used single quotes within your function. HTML can't work out the end of the string and interprets your link as 'javascript:funct_one('. To get around the problem you have to use double quotes so your code would read
Code: Select all
<a href="javascript:funct_one('previewValue','idValue','table1Value')">click here</a>

As your link is now surrounded by double quotes, whatever is within those quotes will work fine.

Now, when you're outputting the HTML, you will have to refer to the double quotes with a backslash to stop them being interpretted literally by the PHP parser.
Code: Select all
echo "<a href="javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')">  click here</a>";

Adding the backslash before the double quote will cause PHP to output the quotation marks (in the case where as string is delimited with double quotes) instead of interpretting it as a delimiter.
Last edited by Jay on Sat Aug 03, 2002 8:38 am, edited 1 time in total.
Jay
 

Re: javascript on the fly with php

Postby WiZARD » Sat Aug 03, 2002 7:11 am

Jay i think that you understand that i wrote in privat messages....
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Re: javascript on the fly with php

Postby Jay » Sat Aug 03, 2002 9:32 am

WiZARD wrote:Jay i think that you understand that i wrote in privat messages....

YGM :wink:
Jay
 

Postby Joan Garnet » Sat Aug 03, 2002 9:33 am

Ok,
I understand.
I didn't know that, would you belive that...

That's a very important thing to know about.
I thought that \" and ' were the very same thing.
When I wrote the code shown above I had a feeling that something was going wrong.
XDDDDD
:)

ThanX
I'm going to fix it right now
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.