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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Input from a popup window to a textarea

    function edInsertImage(myField) {
    var myValue = prompt('Enter The Filename of the picture you want to add', 'Filename.jpg');
    if (myValue) {
    myValue = '<img src=http://localhost/~rr/images/news/'
    + myValue
    + ' />';
    edInsertContent(myField, myValue);
    }
    }

    This is the function i use now to insert a image to my textarea. Now the user has to specify the filename manually.
    I want the user to be able to choose the picture from a popup window, in stead of the prompt way("manual way")

    Here is my code for my planned popup window:
    <b>Your Images:</b>
    <table class='main'>
    <?
    $db->Query("SELECT * FROM Pictures
    WHERE usr_id='".$_SESSION['usr_id']."'
    ORDER BY pic_filename", "pictures");
    while ($pictures=mysql_fetch_assoc($db->res['pictures'])) {
    echo "<tr>";
    echo "<td><img src='/~rr/images/news/" . $pictures['pic_filename'] . "' height='50' width='50'></a></td>";
    echo "<td>" . $pictures['pic_filename'] . "</td>";
    echo "</tr>";
    }

    ?>
    </table>

    This is how i want it to be:

    1. User click Insert image button
    2. User gets the popup window with the list of the pictures(with thumbnails)
    3. User click on one picture then it inserts myValue to my function and closes the popup window and insert the html code for the picture.

    Anyone able to help me with this? i have googled for hours :/

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Add this to the onclick of each image listed in the popup. I assume a textarea in the main page called 'theImg' in a form called 'theForm'. Change as appropriate. If you want the text added instead of changed, make the assignment += instead of just =.


    i.e.
    <img src='whatever.jpg' onClick='choose(this)'>

    Code:
    function choose(img)
       {
       opener.document.forms['theForm'].elements['theImg'].value="<img src='"+img.src+"' />";
       self.close();
       }

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exactly what i need, thanks a lot nikkiH!


  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks alot for this! this is exactly what i was looking for also!

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You need a checking to avoid error when the opener window is already closed.
    Code:
    function choose(img)
    {
       if (opener && !opener.closed) {
          opener.document.forms['theForm'].elements['theImg'].value="<img src='"+img.src+"' />";
       }
       self.close();
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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