Forum Moderators: open

Message Too Old, No Replies

Passing Variable from php to javascript

         

nanat

7:33 am on Nov 30, 2009 (gmt 0)

10+ Year Member



im trying to pass a value from php to JavaScript but it doesnt work.. what's wrong with my code?

function Upload()
{

$rdata'
<a href="login.html?height=150&width=350 rel=\"lightbox\">upload Me</a>';

return $rdata;
}

T_T

daveVk

9:22 am on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That does not look like valid JavaScript, what would a typical value of $rdata be ?

I assume this is part of a PHP file, what does the generated html/javascript look like ?

What is the purpose of the function ?

nanat

12:55 am on Dec 1, 2009 (gmt 0)

10+ Year Member



hi dave.. the function Upload() is an php format file.

i replace my echo statement to $rdata in order for me to get the value and return it with return $rdata;

my problem is this statement inside $rdata rel=\"lightbox\" it seem doesn't work but this codes works
onClick="createNews(\'DivUpload\');" on me

im passing value lightbox to Javascript for me to appear the lightbox form..

hope u understand my english

thx

daveVk

4:00 am on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if $rdata is a number say 7 then it will generate
return 7;
Ok

if $rdata is a text say fred then it will generate
return fred;
NOT Ok, it needs to be return "fred";

onClick="createNews(\'DivUpload\')";
is a valid javaScript statement.

'<a href="login.html?height=150&width=350 rel=\"lightbox\">upload Me</a>'
is not.

It is just a text string,
I assume you want this html string(link) to be inserted into page ?

should read

var link = '<a href="login.html?height=150&width=350 rel=\"lightbox\">upload Me</a>';
.... code to do something with link ....

iroot

9:32 pm on Dec 1, 2009 (gmt 0)

10+ Year Member



Please explain us distinctly how should it work and what's your problem.

nanat

12:36 am on Dec 2, 2009 (gmt 0)

10+ Year Member



thx dave i get it.. my JavaScript dont work because of two Conflict on my Javascript variable. but now its works perfectly now tnx.. ^^


if $rdata is a text say fred then it will generate
return fred;
NOT Ok, it needs to be return "fred";

yes dave. if you will put an string and numeric numbers on $rdata it will return string even if numeric number.. for me this style of coding is so weird because when your inside the $rdata the loops dont work even if you put your codes outside the $rdata but echo works fine..