NYCPHP Meetup

[nycphp-talk] call javascript function from php

Michele Waldman mmwaldman at nyc.rr.com
Tue Jan 20 08:28:31 EST 2009


The source is all javascript.  It's got nothing to do with php.  Should be
on a javascript forum

if (document[c_img].src.indexOf(img1)!= -1) document[c_img].src = img2; 
     else document[c_img].src = img1; 
should be

if (document.getElementById(c_img).src.indexOf(img1)!= -1)
document.getElementById(c_img).src = img2; 
     else document.getElementById(c_img).src = img1; 

looks like you were trying
if (document.all[c_img].src.indexOf(img1)!= -1) document.all[c_img].src =
img2; 
     else document.all[c_img].src = img1; 
document[c_img] dne.

Michele

  _____  

From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of Zakir Tariverdiev
Sent: Tuesday, January 20, 2009 4:24 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] call javascript function from php

 


I don't see the 'img' variable declared anywhere. Is it a JavaScript or PHP
($img) variable?
In the former case, PHP is not needed. 
Assuming the latter case, try this:
(plain HTML here)

<img src="images/bullet_green.png" name="<?php echo $img; ?>" 
     onclick="chng('<?php echo $img; ?>')" />


--- On Mon, 1/19/09, chad qian <nynj.tech at hotmail.com> wrote:

From: chad qian <nynj.tech at hotmail.com>
Subject: [nycphp-talk] call javascript function from php
To: talk at lists.nyphp.org
Date: Monday, January 19, 2009, 11:05 PM

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 LiveT: Keep your life in sync. Check it out.
<http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009>  

_______________________________________________


New York PHP User Group Community Talk Mailing List


http://lists.nyphp.org/mailman/listinfo/talk


  


http://www.nyphp.org/show_participation.php

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090120/213a781d/attachment.html>


More information about the talk mailing list