简体   繁体   English

保存并关闭按钮javascript

[英]Save & Close button 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. 我正在创建一种表单,用户可以通过从下拉菜单中进行选择来选择3种类型的预定义字母和一种自定义字母。 I have a javascript function that opens a popup window when 'custom letter' is chosen, so far so good. 我有一个javascript函数,当选择“自定义字母”时,会打开一个弹出窗口,到目前为止效果很好。 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..... 我正在使用php和javascript,但我认为这里需要一些ajax。

Thanks 谢谢

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. 您可以使用AJAX执行此操作。 When the ajax call returns successfully, close the popup. 当ajax调用成功返回时,关闭弹出窗口。

Just embed the textarea and the button in a form that POSTs to the PHP script that handles the saving. 只需将textarea和按钮嵌入到POST到处理保存的PHP脚本的表单中即可。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM