Hi guys

I'm using the script add_address.php to output a list of email addresses from the message box to allowed me to split the email addresses to add to each comma. I want to output the email addresses from the message box to the text box in the send.php script then close the popup.

Here is the code for add_address.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Add Email Addresses...</title>
    </head>
    <body>
    <form action="send.php" method="post">
    <table>
        <tr>
            <td><textarea name="message" cols="50" rows="20"></textarea></td>

        </tr>

        <td colspan="2" align="left">
           <input type="submit" name="send" value="Add Email" style="height:35px; width:100px">
        </td>
    </table>
    </form>
    </body>

Here is the code for send.php:

<?php
    if (!empty($_POST['message'])) 
    {
        $emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
        $email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
     }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Send Email</title>
    <link type="text/css" rel="stylesheet" href="style.css"  />
    </head>
    <body>
    <form action="pr_send.php" method="POST">
    <table>  
        <!-- <tr>
            <td>From:</td>
            <td><input type="text" name="from"></td>
        </tr> -->
        <tr>
            <td><input type="button" name="to" value="" style="height:24px; width:24px; background:url('addressbook.png'); border:none;" onClick="Popup()"> To:</td> 
            <td><input type="text" name="to" value="<?php if (!empty($email_str)) { echo $email_str; } ?>" style="height:15px; width:650px"></td>
        </tr>
        <tr>
            <td>Subject:</td>
            <td><input type="text" name="subject" style="height:15px; width:650px"></td>
        </tr>
        <tr>
            <td>Message:</td>
            <td><textarea name="message" cols="90" rows="20"></textarea></td>
        </tr>
        <tr>
            <td colspan="2" align="left">
               <input type="submit" name="send" value="" style="height:35px; width:100px; background:url('send.png'); border:none">
            </td>
        </tr>

    </table>
    </form>
    </body>
<script type="text/javascript">
function Popup() 
{
  window.open("add_address.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400");
}
</script>

</html>

What my code have shown, it will output the list of email addresses in the message box and it will split each email to add to each comma then it will redirect to the send.php page to output the list of email addresses in the text box without close the popup. I want to add the list of email addresses in the message of that popup when a button is clicked and I want to post list of email addresses from message box to the text box then close the pop up.

Here is for example:

I click on the address book to open the add_address.php script to display the popup.

http://oi62.tinypic.com/2w53g2g.jpg

When the popup is display, I add the list of email addresses in the message box.

http://oi57.tinypic.com/15fqckm.jpg

When I click on a submit button, it will split the email addresses to add to each comma and it will close the popup then it will post the email addresses from a message box to a text box.

http://oi60.tinypic.com/2lne9gx.jpg

How I can do that?

This is off the top of my head but I think you can assign your window to a variable eg:

var myWin = window.open("add_address.php...

then later I think you can go myWin.close()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.