Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image onclick (PHP)

    Hello,
    Hope someone can help me, I dont know were to put this thread because it has javascript and some PHP. Here is my question: I have a list of images in my folder named: 1.jpg, 2.jpg, 3.jpg etc... All images are displayed on a white div, and when users click on the image, the backgound of the div changes to orange. But I dont know how to reverse that, from orange to white, onclick. Thanks!


    PHP Code:
    <script type="text/javascript">
        <?php 
    $i 
    1;
    while (
    $i 6)
    {
        
    ?>     
    function ponerborde<?php echo $i?>(here)
    {
            var imgTag = "<div style='height:77px; width:102px; background-color: #F60; display:table-cell; position:relative; vertical-align:middle;'><img src='<?php echo base_url().$i?>.jpg' onclick='ponerborde<?php echo $i?>(<?php echo $i?>)'/>";
        
        var obj = document.getElementById(here);
        obj.innerHTML = imgTag;
    }
    <?php 
    $i
    ++;
    }
    ?>
    </script>

    <?php 
    $i 
    1;
    while (
    $i 6)
    {
        
    ?> 
    <div id="<?php echo $i?>" style="display:table; float:left;text-align:center;vertical-align:middle;">
    <div style="height:77px; width:102px; background-color: #FFF; display:table-cell; position:relative; vertical-align:middle;">
    <img src="<?php echo base_url().$i?>.jpg" onclick="ponerborde<?php echo $i?>(<?php echo $i?>)"/>
    </div>
    </div>
    <div class="vacio">
    </div>
    <?php 
    $i
    ++;
    }

    ?>

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Thumbs up

    seven-togglers

    Click the first one...
    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

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