PDA

View Full Version : possible use php in javascript ?



zodehala
12-23-2007, 10:11 PM
E.G. we can use html in php like


<?php echo ' <!--HTML codes-->' ; ?>

is it possbile to use php in javascript ?


<script language="javascript">
function example(){
//php codes
}
</script>

Nightfire
12-23-2007, 11:06 PM
You can have php write things into the javascript, but you can't have javascript parse/execute php.

oesxyl
12-23-2007, 11:09 PM
<script language="javascript">
function example(){
//php codes
}
</script>

Add after posting: sorry I missunderstand the question!!!

yes is possible, php generate the page on the server after browser request but before the browser see what is in that page, :)

best regards

Jesuspwnt
12-23-2007, 11:57 PM
E.G. we can use html in php like


<?php echo ' <!--HTML codes-->' ; ?>

is it possbile to use php in javascript ?


<script language="javascript">
function example(){
//php codes
}
</script>

these two are totally different..
the first echo's html tags from a php script
the second uses javascript to try to execute php

thindrakhya
12-24-2007, 12:35 AM
It depends what u want ur script to do,

If we want to insert any data into sql or want to display then usually i use


window.location = ....php;

and then use redirection after sql query

If u want to change anything then use ajax

There is no direct way to do it but u can work around these things

zodehala
12-24-2007, 04:55 AM
It depends what u want ur script to do,

If we want to insert any data into sql or want to display then usually i use


window.location = ....php;

and then use redirection after sql query

If u want to change anything then use ajax

There is no direct way to do it but u can work around these things

for example define COOKIE or ragister in mySQL dB

SeeIT Solutions
12-24-2007, 07:00 AM
You can do it behind the scenes with AJAX. That way information gets sent to PHP and back without the user really knowing.