SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Image swap problem

    Some images are coming dynamically by server side code and those are placed in the <td><img src="..." ... /> </td> of a table.
    Can anyone help me with the javascript code by which I can swap the images and thereafter change their order in database ?
    Thank you.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <script type="text/javascript">
        function swapImage(newImage, which) {
            if(typeof(which) == 'string')
                which = document.getElementById(which);
    
            which.src = newImage;
        }
      </script>
     </HEAD>
    
     <BODY>
      
        <table>
            <tr>
                <td><img src="{image}" onmouseover="swapImage('{image2}', this);" onmouseout="swapImage('{image}', this);" /></td>
            </tr>
        </table>
    
     </BODY>
    </HTML>
    The database stuff will have to be asked in a sperate forum, basically you can put the url to the main image in {image} and the swap image {image2}

    Hope that helps.


  3. #3
    SitePoint Addict
    Join Date
    Apr 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry !
    I think that I have not been able to make you understand my problem.

    Actually what I wanted to mean by swap is to drag-drop an image and then change its position.

    http://www.java2s.com/Code/JavaScrip...sortslides.htm

    I have implemented the above code but facing some problems (the lower portion of the page the rectangular images).
    It is showing some errors in I.E.

    If the number of images are less than 3 the swaping does not run.
    Do you know any way how to solve it ?

    And how can I have the serial numbers as I can store those in a PHP array ?

    Thank you.


Bookmarks

Posting Permissions

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