NYCPHP Meetup

NYPHP.org

[nycphp-talk] call javascript function from php

Darryle Steplight dsteplight at gmail.com
Mon Jan 19 23:16:40 EST 2009


Chad,
     It doesn't look like you need PHP at all here. Try the following,
Replace:
     <?php echo "<a href=\"javascript:chng('img')\"><img
src=\"images/bullet_green.png\" name=\"img\"></a>" ;?>
With:
     <img src=\"images/bullet_green.png\" name=\"img\" onClick="chng(img)">

On Mon, Jan 19, 2009 at 11:05 PM, chad qian <nynj.tech at hotmail.com> wrote:
> I want to call javascript function from php.But I fail.
> Here is the source code,any help?Thanks!
>
> chad
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
>    <script language="javascript">
>      function chng(c_img) {
>   img1 = "images/bullet_green.png";
>      img2 = "images/bullet_red.png";
>      if (document[c_img].src.indexOf(img1)!= -1) document[c_img].src = img2;
>      else document[c_img].src = img1;
>   }
>    //}
>    </script>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <title>Untitled Document</title>
> </head>
> <body>
> <?php echo "<a href=\"javascript:chng('img')\"><img
> src=\"images/bullet_green.png\" name=\"img\"></a>" ;?>
> </body>
> </html>
>
> ________________________________
> Windows Live™: Keep your life in sync. Check it out.
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>



More information about the talk mailing list