SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return the Image name only?

    Hi Guys,

    I have a script that when you click on an image it returns the full path of the clicked on image to a textbox on another page. Here's a snippett:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>STFC Site Admin</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="../include/styles.css">
    <script type="text/javascript">
    function returnInfo(imgURL) {
    opener.document.news.front_picture.value=imgURL;
    this.close();
    }
    </script>
    </head>
    
    <body>
    
    echo '<div align="center"><a onClick="returnInfo(this.firstChild.src);return false;"><img src="../../players_pictures/fronts/'. $rows['thumb_name'] .'"></a></div><br />';
    ?>
    
    </body>
    </html>
    But how could I get it to only put the image name in that textbox ie picture.jpg rather than www.myurldomainname.com/image/picture.jpg?

    Thanks

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Use the split() method followed by pop(). So:
    Code:
    function returnInfo(imgURL) {
    var bits = imgURL.split('/');
    opener.document.news.front_picture.value=bits.pop();
    this.close();
    }
    May I ask what this.close() is supposed to be for? Also, I would recommend a google search on "unobtrusive javascript".

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Works a treat. That closes the pop-up window after clicky.

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes of course. window.close() is more traditional, it's just that in this case this = window.


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
  •