You need to write a web text editor that will send data from text forms to the server. As I understand it, it was possible to do this via XMLHttpRequest (each form is sent separately, the page is not reloaded). Theoretical code:

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> </head> <body> <tr><td>Text1</td><td>Text2</td><td><textarea>Text3</textarea><button onclick = "send_data()" id="button">Отправить</button></tr> <script> function send_data() { button.innerHTML = ' ... '; s = button.previousElementSibling; var text = s.value; var http = new XMLHttpRequest(); var url = "get_data.php"; http.open("POST", url, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(text); } </script> </body> </html> 

How can I get the send_data function to identify the button that was pressed (to get the desired text) (id only 1) and how to write a php file that will receive the information and write it to the file?

  • send_data(this) - Grundy
  • Can you give more details? It emphasizes me in red, but, alas, it does not work faster from this. - Jedi Knight
  • faster and should not work, should just work. Since you wanted the button that was pressed, you got it like this - Grundy
  • This should have been added to onclick. Now without red, but nothing happens when pressed. Tell me, please, what button to change. js i don't know well on this.button replaced, it seems does not work. - Jedi Knight
  • Yeah, figured out. this in onclick, in function send_data (obj), which caused the element - obj - Jedi Knight

1 answer 1

When you click on this element, send_data is called, where this element is transmitted, with which you can perform some actions.

 <span class="input-group-addon btn btn-primary" onclick="send_data(this)">Send</span> function send_data(button) { button.innerHTML = ' ... '; }