Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    PHP code in javascript

    Hi

    I have a popup script written in javascript and I want to add some php code there.

    This is the beginning of the code:

    var defaultMenuWidth="150px" //set default menu width.

    var linkset=new Array()
    //SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

    linkset[0]='<a href="http://dynamicdrive.com">Dynamic Drive</a>'
    linkset[0]+='<hr>' //Optional Separator
    linkset[0]+='<a href="http://www.javascriptkit.com">JavaScript Kit</a>'
    linkset[0]+='<a href="http://www.codingforums.com">Coding Forums</a>'
    linkset[0]+='<a href="http://www.cssdrive.com">CSS Drive</a>'
    linkset[0]+='<a href="http://freewarejava.com">Freewarejava</a>'

    linkset[1]='<?php echo "Something"; ?>'
    linkset[1]+='<a href="http://cnn.com">CNN</a>'
    linkset[1]+='<a href="http://news.bbc.co.uk">BBC News</a>'
    linkset[1]+='<a href="http://www.washingtonpost.com">Washington Post</a>'
    How can I modify this script to make the php work properly?

    See this link for whole code and more info:
    http://www.dynamicdrive.com/dynamicindex1/popit.htm


    Thanks in advance

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Exactly what is not working with it? Is the file's extension 'php'? Is the server you're running it on enabled to use PHP to begin with or are you testing it locally without a server running?
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • Users who have thanked Eldarrion for this post:

    levani (03-19-2009)

  • #3
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    where is YOUR code? what's not working?

    that should work fine if it's a php page and that echo gets processed as the page is being built.

  • Users who have thanked ohgod for this post:

    levani (03-19-2009)

  • #4
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Well, the extension was .js and I changed it to php. Now everything seems to work fine

    Will all php code work properly as in standard php file?

  • #5
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Don't see why it shouldn't. <?php ?> inside <script> tags is interpreted fine provided the server knows to look for it and supports it.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • Users who have thanked Eldarrion for this post:

    levani (03-19-2009)

  • #6
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    OK, thank you very very much.

    Great forum!!!


  •  

    Posting Permissions

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