Results 1 to 4 of 4
  1. #1

    PHP and Javascript question

    Two seperate questions, hopefully someone can help!

    1. Does anyone know the javascript code I could use to make a toggle switch type image? Basically, the image is one state, then when clicked on, swaps to another image, then when clicked on again, back to the start. It's for an on off switch. I've tried searching the net, nothing seemed to cover it.

    2. Does anyone how to write the PHP eregi function to check a string for:

    a & b || a & c?

    It doesn't seem to support more than one term.

    Any help is much appreciated!

  2. #2
    Join Date
    May 2003
    In a home
    Some simple code through Javascript should fix your problem. There is an event called onclick major browsers use to run a line of code.

    <title>Mouse Switch</title>
    <script language="Javascript" type="text/javascript">
    var switchedImage = new Image(width,height);
    switchImage.src = "path/to/image.jpg";
    function switch(id,imSrc)
                   document.getElementById(id).src = imSrc;
    <a href="Javascript: switch('switch01','path/to/image.jpg');" target="_self"><img id="switch01" src="image.jpg" width="#" height="#" border="0" /></a>
    Note: For some reason the board is putting javascript in the href="" with a space between java and script. That is supposed to be one word.

    As far as your PHP problem is concerned I'd probably try putting those into parenthesis.

    PHP Code:
    ($a $b) || ($a $c
    I don't know much on that particular function in PHP so I could be wrong, but I'm guessing that is where you are making a mistake. You should check the online documentation at and look up that function.
    Last edited by Misto-Roboto; 03-21-2004 at 06:08 PM.

  3. #3
    Join Date
    Jan 2003
    Perth, WA, Australia
    Put this in the <head></head> of your HTML
    <script type="text/javascript">
    	// Preload
    	window.onload = function() {
    		document.createElement('img').src = 'image2.jpg';
    	// swapImage() function
    	function swapImage(obj,img1,img2) {
    		obj.src = (obj.src == img1) ? img2 : img1;
    And you can use it like this
    <img src="image1.jpg" width="N" height="N" onclick="swapImage(this,'image1.jpg','image2.jpg');" border="0">
    As for the PHP question... I don't exactly understand what you mean, care to give an example string and use? :: coming soon

  4. #4
    Join Date
    Feb 2004

    You can have a look into this URL for your toggling problem (Javascript). Here you can find javascript that may fix your prob....



Posting Permissions

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