I started learning JavaScript, now I train to write code, but for some reason I can’t write what I want. Google did not help much, maybe I'm not looking there. I have a form with input name, surname. Suppose I make a gallery with a form. I want the person to enter his name and surname, press the button and go to the next page, where his Name and Surname with a greeting would be displayed in a div or span (Hello, Ivan Ivanovich!). Now for me it does not matter whether the data from the form will be sent to the database or not (PHP and mySQL have not yet been taught), I just want to do something that does not work. I do not have enough practice, who knows what, advise, maybe there is some resource. Where can I practice pure JS? Perhaps you can do something like this on jQuery. Below I attach my code, I hope for help.

<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <!-- Этот код на первой странице --> <div> <input type="text" name="name" id="name"> <input type="text" name="surname" id="surname"> <button id="next" hraf="2 страница">Далее</button> </div> <!-- Этот код на второй странице --> <div> <p>Приветствуем, <span id="theName">...</span> <span id="theSurname">...</span>!</p> </div> <script> // Забираем значение из input var theName = document.getElementsById("name")[0]; //забрали имя var val1 = theName.value; var theSurname = document.getElementsById("surname")[0]; //забрали фамилию var val2 = theSurname.value; // Отдаём значение в span (html) var output1 = val1; document.getElementById("theName").innerHTML = output1; //отдали имя var output2 = val2; document.getElementById("theSurname").innerHTML = output2; //отдали фамилию </script> </body> </html> 

  • There is such a thing as a web site on one page. This allows you to change the content on the screen without moving to a new html-file. In your case, you must first show the first part of the html elements of the page, and the rest is hidden. After entering the name, the input form must be hidden or even deleted, and the rest of the elements are shown, with the name already spelled out - Sergey Nudnov
  • So javascript works within only one page? - Daniel Kedrov
  • Yes, js works within one page - Alexandr Tovmach am

0