...

View Full Version : Input from a popup window to a textarea



vingne
08-15-2005, 01:21 PM
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 :/

nikkiH
08-15-2005, 02:13 PM
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)'>



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

vingne
08-16-2005, 07:43 AM
Exactly what i need, thanks a lot nikkiH!

:thumbsup:

Scrowler
02-03-2006, 02:46 AM
thanks alot for this! this is exactly what i was looking for also! :)

glenngv
02-03-2006, 11:12 AM
You need a checking to avoid error when the opener window is already closed.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum