Log in

View Full Version : php in dhtml causing error



anamika
06-09-2010, 09:10 AM
Hi,
I have a dhtml code in php file.
Inside the dhtml function I have a php function call.
The function call is not being executed.
Browser is giving a javascript error .

The function call is as


var info='';

info +='<?php mTypes( 'wordc', 'm types are','Individual.' ); ?>';

Am very new to php,
can anyone resolve the issue.
Thanks.

bluewalrus
06-09-2010, 12:37 PM
If this doesnt work post the function code.


info +='<?php echo mTypes( 'wordc', 'm types are','Individual.' ); ?>';

djr33
06-09-2010, 06:27 PM
WHEN are you executing this?

PHP is processed entirely, then the text is sent to the browser. AFTER that the browser executes Javascript.

You can NEVER have PHP executed within Javascript. That's just now how the languages work.

There may be a better way around it, but the method you are using will not work if you are trying to execute PHP while you execute Javascript.


What this will do is execute ONE time, giving the Javascript a starting value, but it will NOT execute after that-- just once.
If you want it to only execute once like that, then this can work.

If you need to have the PHP execute while the Javascript executes, you need to use something called Ajax-- it's a broad topic so try searching on google.