javascript on the fly with php

A

Anonymous

Guest
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:
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";
The function:###############################

Code:
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!
:)
 
Joan Garnet said:
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:
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";
The function:###############################

Code:
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/StringTheory/page2.html
or
http://www.zend.com/zend/tut/using-strings.php
 
Joan Garnet said:
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:
echo "<a href='javascript:funct_one('".$row["preview"]."','".$row["id"]."','".$table1."')'>  click here</a>";
The function:###############################

Code:
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:
<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:
<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:
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.
 
Jay i think that you understand that i wrote in privat messages....
 
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
 
Back
Top