There is a data-lesson attribute and there are a couple of activities with the same attribute, but (as is obvious) with different values. When you click on the button, the value of the data-lesson attribute should be taken and inserted into the input . I made about a working code, but when I click on another lesson, the value in the input does not change
Here is the code
$(document).ready(function(){ $('.openAlert').click(function() { $('.form').addClass('active'); var hey = $('.openAlert').attr('data-lesson'); $('#curs_little').attr('value', hey) }); }) <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <a class="btn btn-xl openAlert" data-lesson="Мероприятие"> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-label white-btn-label">Записаться</span> </a> <a class="btn btn-xl openAlert" data-lesson="Подарочные сертификаты"> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-label white-btn-label">Записаться</span> </a> <a class="btn btn-xl openAlert" data-lesson="Детские развивающие группы"> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-paint"></span> <span class="btn-label white-btn-label">Записаться</span> </a> <!-- Сам input --> <div class="form-control"> <input type="text" placeholder="Курс" required data-validation-required-message="Выберите курс!" name="curs_little" id="curs_little"/> </div>
var hey = $('.openAlert').attr('data-lesson');replace$('.openAlert')with$(this)- Dmitry