For example, I have one form for entering a nickname:

<input type='text' name='nick'> 

And a field for another text:

 <input type='text' name='text'> 

How to make it so that when I switched from the nick field to another, the php script was executed and, if necessary, displayed the password field? Without reloading the page naturally.

It is required to check if such a nickname is registered in the system, then when adding text, a person must enter his password.

  • one
    [AJAX] ( google.com/m?q=Ajax&client=ms-opera-mobile&channel=new ) [DOM] ( google.com/… ) 1. Asynchronously ask the server if there is such a nickname in the system. 2. The server must answer yes or no. 3. See server response. 4. Notify the user in accordance with the result of the response - ReinRaus
  • in fact, I can send a request, but how can I find out that the user has moved to another field? - Emil Sabitov
  • one
    execute the Ajax request for the focus event of the "text" field, or if you lose the focus of the "nick" field. Depending on the page logic. - Vitalii Maslianok

1 answer 1

Here is an example js handler:

 //событие сработает при потере фокуса поля nick $('#nick').blur(function() { //посылаем запрос на некую страницу test.php $.ajax({ type: "POST", url: 'ajax/test.php', data: { nick: $('#nick').val() }, dataType: "text", success: function(data) { //при успешном исходе получаем данные в перменную data и обрабатываем их if (data=='show_pass_input') { $('#pass').show(); } else { $('#pass').hide(); } }, error:function (xhr, ajaxOptions, thrownError){ //если ошибка аякса, то выведем ее alert(xhr.status); alert(thrownError); } }); }); 

Next, we create a PHP page, where we take the nick $_POST['nick'] variable, process it and, say, if we need to show the password field, then output: echo("show_pass_input"); (as an example)

  • one
    Thank you very much! Just what you need. Now I have found my old book, I was looking for ways there. But did not find) - Emil Sabitov