Hello HashCode.

There is a button and there is a field, I need to make sure that when I click on the button, the word “Hello” is added to the field.

Code:

<form action = "" method = "post"> <input type = "submit" value = "Добавить текст" /> <br /><br /> <input type = "text" name = "text" /> </form> 

    1 answer 1

     <form action = "" method = "post"> <input type = "submit" name="button_name" value = "Добавить текст" /> <?php $text = ''; if(isset($_POST['button_name'])){ $text = 'привет'; } ?> <input type = "text" name = "text" value = "<?php print $text; ?>" /> </form> 

    Whit. But it is better to do it through JS. It will work many times faster, the restart will disappear.

     <form action = "" method = "post"> <input type = "submit" onclick="document.getElementById('text').value='Привет'" value = "Добавить текст" /> <input type = "text" name = "text" id="text" value = "" /> </form> 
    • It works, and if for example a field on one page, and a button on another? So you can do? - Angus123
    • one
      In the action field specify the address of the page on which the field. Move the PHP piece to it: <? Php $ text = ''; if (isset ($ _ POST ['button_name'])) {$ text = 'hello'; }?> <input type = "text" name = "text" value = "<? php print $ text;?>" /> - knes
    • And through js you can transfer information between pages? I just have the second page loaded in the iframe, look at what I need to learn to do, I have a chat: chat-profit.org.ua/index.php that's where I need to make a button like a message in the Enter message field, should add the nickname of the one who wrote this message. Login: Angus123 Password: 159357 For a clearer explanation, this is how Quotes on the forum. link is not advertising is just my project for which I want to do it. - Angus123
    • one
      can and should be! However, if this is a chat, it's better to use ajax, otherwise, I'm afraid the answer will be only you see. Var iframePageDocument = document.getElementById (Id of frame) .contentDocument; onclick = "iframePageDocument.getElementById ('text'). value = 'Hi'" - knes