保存并关闭按钮javascript

I'm creating a form where user can select between 3 types of predefined letters and a custom one by selecting from a drop down menu. I have a javascript function that opens a popup window when 'custom letter' is chosen, so far so good. What i want is on the popup window to have a text area where user can write whatever he wants and finally press a button which saves that text written and close that popup.... is it possible?

I'm using php and javascript, but i presume some ajax will be needed here.....

Thanks

Just embed the textarea and the button in a form that POSTs to the PHP script that handles the saving.

<form action="save_stuff.php" method="post" onsubmit="window.close();">
    <textarea name="letter" cols="50" rows="50"></textarea>
    <input type="submit" value="Save & Exit" />
</form>

Inside the popup, you would have a form that submits the contents of the text area to your server (which will save it to your DB). You could use AJAX to do this. When the ajax call returns successfully, close the popup.