var id_name_var id_name_var = "Name" function Search_user() { var search = document.getElementById("search-user-input").value; var h4 = document.createElement('label') if (id_name_var == "Name") { h4.innerText = "Найдено по запросу " + search + ":" } else { h4.innerText = "Найдено по ID " + search + ":" } h4.className = "h4" document.body.append(h4) var a = document.createElement('a') a.className = "a"; a.innerHTML = '<a href="" style="color: rgb(87, 59, 7); text-decoration: none"><div class="contact-data"><img src="" alt="" class="img-cont"><label class="contact-name">' + search + '</label><br><label class="message-text-cont">Вы искали его(-ё)?</label></div></a>' document.body.append(a); } function id_name() { var id_name_val = document.getElementById("id-name") var input = document.getElementById("search-user-input") if (id_name_val.value == "Поиск по ID") { id_name_val.value = "Поиск по Имени" input.placeholder = "ID пользователя" id_name_var = "ID" input.value = "" } else { id_name_val.value = "Поиск по ID" input.placeholder = "Имя пользователя" id_name_var = "Name" input.value = "" } }
<!DOCTYPE html> {% load static %} <html lang="ru"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="{% static "css/Search.css" %}" /> <title>Поиск пользователя</title> </head> <body bgcolor="orange"> <div id="div-title"> <img id="img-icon" src=""> <a href="{% url 'main' %}"><button id="btn-icon">Finter</button></a> <a href="{% url 'search_user' %}"><button class="btn-title">Найти</button></a><!-- --><a href="{% url 'frends' %}"><button class="btn-title">Друзья</button></a> <a href="{% url 'sign_in' %}"><button class="btn-title" id="btn-ent">Войти</button></a> <a href="{% url 'registration' %}"><button id='btn-reg'>Регистрация</button></a> </div> <div id="content"> <div id="search-user"> <input type="search" id="search-user-input" placeholder="Имя пользователя" maxlength="45" required><!-- --><button onclick="Search_user()" id="search-user-button">></button> <input type="button" onclick="id_name()" id="id-name" value="Поиск по ID"> </div> <hr id="search-user-hr"> </div> </body> </html> <script src="{% static "JS/JS Finter.js" %}"> alert('Подключение к JavaScript прервано!'); </script>