Results 1 to 3 of 3

Thread: php in dhtml causing error

  1. #1
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php in dhtml causing error

    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.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    If this doesnt work post the function code.

    PHP Code:
    info +='<?php echo mTypes'wordc''m types are','Individual.' ); ?>';
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •