Can Javascript be called from PHP?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Can Javascript be called from PHP?

    Can Javascript be called from PHP? I was just trying to implement a little
    print button that appeared if a certain condition was met like this:

    <?

    if ($reject=="0") {echo "<a href="javascript:print()""><img
    src="images/print_button.gif" width="82" height="22" border="0"></a></p>;};

    ?>

    but this fails spectacularly! I'm sure there is a good reason why - if only
    I could poinpoint what it is!

    Anybody care to enlighten me?

    THANKS!

    Steve


    Steve Guest

  2. Similar Questions and Discussions

    1. #39868 [NEW]: Destructor is called allthought constructor is never called
      From: jb at ez dot no Operating system: Kubuntu 6.10 PHP version: 5.2.0 PHP Bug Type: *General Issues Bug description: ...
    2. #39678 [Opn->Bgs]: __set and __get not called where a class attribute is called statically
      ID: 39678 Updated by: tony2001@php.net Reported By: denis at edistar dot com -Status: Open +Status: ...
    3. #39678 [NEW]: __set and __get not called where a class attribute is called statically
      From: denis at edistar dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem Bug...
    4. Include javascript in a javascript file
      Hello, Is there a way to include a javascript file from WITHIN a javascript file? Something similar as in the "#include" directive in C++? ...
    5. need javascript staff (anyone who knows javascript peroid) (READ)
      hey its me ultimategamerx and im back in some clothes lol i need some people who know java script i need help please reply if ya know some
  3. #2

    Default Re: Can Javascript be called from PHP?

    You can't put quotes in quotes!

    Try

    <?

    if ($reject=="0") {
    echo "<a href=javascript:print()><img src=images/print_button.gif width=82
    height=22 border=0></a></p>";
    }


    ?>





    "Steve" <luckylucky200@hotmail.com> wrote in message
    news:4d2307447503850bd336e6e688825024@news.teranew s.com...
    > Can Javascript be called from PHP? I was just trying to implement a little
    > print button that appeared if a certain condition was met like this:
    >
    > <?
    >
    > if ($reject=="0") {echo "<a href="javascript:print()""><img
    > src="images/print_button.gif" width="82" height="22"
    border="0"></a></p>;};
    >
    > ?>
    >
    > but this fails spectacularly! I'm sure there is a good reason why - if
    only
    > I could poinpoint what it is!
    >
    > Anybody care to enlighten me?
    >
    > THANKS!
    >
    > Steve
    >
    >

    Matt Foster Guest

  4. #3

    Default Re: Can Javascript be called from PHP?

    "Ian.H" <ian@WINDOZEdigiserv.net> wrote in message
    news:pan.2004.04.05.14.51.27.844000@bubbleboy.digi serv.net...
    > [ Rearranged into correct Usenet, chronological order ]
    >
    >
    > > "Steve" <luckylucky200@hotmail.com> wrote in message
    > > news:4d2307447503850bd336e6e688825024@news.teranew s.com...
    > >> Can Javascript be called from PHP? I was just trying to implement a
    little
    > >> print button that appeared if a certain condition was met like this:
    > >>
    > >> <?
    > >>
    > >> if ($reject=="0") {echo "<a href="javascript:print()""><img
    > >> src="images/print_button.gif" width="82" height="22"
    > > border="0"></a></p>;};
    > >>
    > >> ?>
    > >>
    > >> but this fails spectacularly! I'm sure there is a good reason why - if
    > > only
    > >> I could poinpoint what it is!
    > >>
    > >> Anybody care to enlighten me?
    > >>
    > >> THANKS!
    >
    >
    > On Mon, 05 Apr 2004 14:26:04 +0000, Matt Foster wrote:
    >
    > > You can't put quotes in quotes!
    > >
    > > Try
    > >
    > > <?
    > >
    > > if ($reject=="0") {
    > > echo "<a href=javascript:print()><img src=images/print_button.gif
    width=82
    > > height=22 border=0></a></p>";
    > > }
    > >
    > >
    > > ?>
    >
    >
    > Don't use this! HTML attribute values should be quoted themselves also.
    >
    > if ($reject == 0) {
    > echo '<a href="javascript:print();"><img src="images/print_button.gif"
    > width="8px" height="22px" border="0"></a>';
    > }
    >
    >
    > Notice here also that I deliberately left the quotes out arout the 0 in
    > the if() call. Unless you _really_ mean a string containing a zero char,
    > then the quotes aren't required. Both work... but one is _preferred_ over
    > the other =)
    >
    > The other thing slightly differnt.. is I've used ' ' (single quotes) for
    > the echo call. As you have no $vars to parse within the string... there's
    > no need to use double-quotes. This is an aside.. an optimisation..
    > although if your application ever relies on this for noticable
    > optimisation, you have severe issues elsewhere.
    >
    > One last thing I'm just throwing in FWIW and not PHP related... your
    > 'javascript:print()' call.. this should really use a return call:
    >
    >
    > return print_page();
    >
    >
    > or similar and have your print definitions within that function. This
    > should then help in situations where Javascript isn't available to the
    > browser:
    >
    >
    > <a href="/print.php" onlick="return print_page();" ...>Print</a>
    >
    >
    > or something similar.
    >
    > Hope this is read as constructive rather than criticism =)
    >
    >
    >
    > Regards,
    >
    > Ian
    >
    > --
    > Ian.H
    > digiServ Network
    > London, UK
    > [url]http://digiserv.net/[/url]
    >
    Thanks Again - you guys saved my life today! - Those damn single and double
    quotes - I'll get em one day!

    Steve


    Steve Guest

  5. #4

    Default Re: Can Javascript be called from PHP?

    use this
    [CODE]
    <?php

    if ($reject == 0)
    {
    echo "<a href=\"javascript:print()\"\"><img
    src=\"images/print_button.gif\" width=\"82\" height=\"22\"
    border=\"0\"></a></p>";
    }


    ?>


    Steve wrote:
    > Can Javascript be called from PHP? I was just trying to implement a little
    > print button that appeared if a certain condition was met like this:
    >
    > <?
    >
    > if ($reject=="0") {echo "<a href="javascript:print()""><img
    > src="images/print_button.gif" width="82" height="22" border="0"></a></p>;};
    >
    > ?>
    >
    > but this fails spectacularly! I'm sure there is a good reason why - if only
    > I could poinpoint what it is!
    >
    > Anybody care to enlighten me?
    >
    > THANKS!
    >
    > Steve
    >
    >
    Smifffy Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139