Re: Using javascript function from php

From: Date: Fri, 11 Mar 2005 06:09:10 +0000
Subject: Re: Using javascript function from php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-210495@lists.php.net to get a copy of this message
It's OK I worked it out. On Fri, 11 Mar 2005 15:44:55 +1100, <b@rbz.biz> wrote:
Hi, I am just learning php, and am currently converting some jsp pages to php. I used the follwing code in jsp to toggle between two images <SCRIPT type="text/javascript" language=javascript> function toggle(imagename,src1,src2){
     if(document.images && document.images[imagename])
         {
         image1=new Image;
         image1.src=src1;
         if(document.images[imagename].src != image1.src){document.images[imagename].src = image1.src}
         else{document.images[imagename].src=src2}
         }
} </SCRIPT> start code snippet............. out.println("<A"); out.println("onclick=\"toggle('" + child + "image','images/" + type + ".jpg','images/" + childimg "');return(false);\""); out.println("><img src='images/" + type + ".jpg' alt='' name=" + child + "image></a>"); out.println("<input type=hidden name=" + child + " value='" + childimg + "'>"); end code snippet............... I have tried many different ways to achieve this in php, but nothing works. This is my latest attempt start code snippet............. print("<A href=\"javascript:;\" onclick="); echo "\"if(document.images && document.images[" . $child . "image])\n"; echo " {\n"; echo " image1=new Image;\n"; echo " image1.src=images/$type.jpg;\n"; echo " if(document.images[" . $child . "image].src != image1.src){document.images[" . $child . "image].src = image1.src}\n"; echo " else{document.images[" . $child . "image].src=images/$childimg}\n"; echo " }\n"; echo "};\n"; echo "return(false);\">\n"; print("<img src='images/$type.jpg' alt='' name=" . $child . "image>\n</a>\n"); print("<input type=hidden name=$child value='$childimg'>\n"); end code snippet............. Could someone please let me know how to do this Cheers Barb
-- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

« previous php.general (#210495) next »