#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    13
    Rep Power
    0

    important: links with javascript functions not working


    Hi, the code:
    <a href="javascript:sections('economics')">click here</a>
    is in an html file called menu.htm and works if I load the html file directly in the browser. But no longer works if I include the HTML file in a PHP file as follows:

    <div id="right" align=right>
    <?php
    $base = "http://www.myPage.com/site/menu/";
    echo ("<BASE HREF=\"$base\">\n");
    require('site/menu/menu.htm');
    ?>
    </div>

    If I take out the base statement it also does not work. When I click the link a new browser window opens with the title "Cannot find server" with "javascript:sections('economics')" in the address line and inside the page it says "The page cannot be displayed".

    But code will work fine if I change the link code in "menu.htm" to be as follows:
    <a href="" onclick="javascript:sections('economics'); return false">click here</a>

    I have to use the link in the non-working format in a particular situation and thus need to know what I am doing wrong

    Thanks,
    Salam
    Last edited by Salam; June 5th, 2003 at 06:29 AM.
  2. #2
  3. Second highest poster :p
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2001
    Posts
    7,322
    Rep Power
    33
    What is the PHP code you use for the first one.

    Javascript is client side, PHP is server side. Javascript doesnt even know it was printed by PHP.

    The line should look like this:

    PHP Code:
    echo "<a href=\"javascript:sections('economics')\">click here</a>"
    Is that what you have?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    13
    Rep Power
    0
    Hi, I edited the description of the problem above to make it more clrear.

    Thanks,
    Salam
    Last edited by Salam; June 5th, 2003 at 06:30 AM.

IMN logo majestic logo threadwatch logo seochat tools logo