TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   can i incorporate javascriptin php? (http://www.talkphp.com/general/2669-can-i-incorporate-javascriptin-php.html)

kororo203 04-21-2008 01:32 AM

can i incorporate javascriptin php?
 
don't know where to postthis but i yhink it ismore aboout php..

i need some clarifications...
lets say that i have a javascript function..
<script>
var i =0;
function xxxx ()

{

if (i == 1)
php expression }
else if (i == 2)
php expression
}
</script>

is this possible?

thanx...

Orc 04-21-2008 01:39 AM

What? This forum is for php, not javascript, I suggest a mod to move this to the javascript forum. oh and no, must be in the scope.

Also, you can put javascript in php, just do an echo or print | printf

PHP Code:

$js=array();
$js[0]="<script>
var i =0;
function xxxx ()

{

if (i == 1)
php expression }
else if (i == 2)
php expression
}
</script>"
;

printf('%s',$js[0]);


#You can also do an sscanf and format it into another variable
#without it outputting
$f_js sscanf($js[0],'%s'); 


kororo203 04-21-2008 01:46 AM

but how bout vice versa?

inside the java script is a php script? can that be possible and how because i think document.write doesn't work for it...

Orc 04-21-2008 01:46 AM

Quote:

Originally Posted by kororo203 (Post 13688)
but how bout vice versa?

inside the java script is a php script? can that be possible and how because i think document.write doesn't work for it...

no javascript is client side, php is server side, it's impossible.

kororo203 04-21-2008 01:51 AM

thanx.. than ill just use javascript inside php statements
thanx for the help...

Orc 04-21-2008 01:53 AM

Quote:

Originally Posted by kororo203 (Post 13690)
thanx.. than ill just use javascript inside php statements
thanx for the help...

Yeah, that's what PHP is good for, just add the php variables in the javascript strings. :) like so

PHP Code:

$var2="var bar = \"foo\";"
$var="<script>$var2</script>"

this would output $var2 into the quotations, it's good. :]


All times are GMT. The time now is 04:41 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0