A
A
Alexander2018-11-28 15:25:16
JavaScript
Alexander, 2018-11-28 15:25:16

How to pass link attribute to modal window?

Greetings!

I am making an order form. The form opens in a modal window, fancybox3.
There are a lot of products on the page, making a modal window with a form for each is nonsense.
Help implement the transfer of the product name to the form, depending on the link with which it was opened.
It is necessary to extract the value of the data-zakaz attribute from the link and place it in the input with name=zakaz

<a data-fancybox data-src="#modal" data-zakaz="Название товара 1" href="javascript:;">Заказать</a>
<a data-fancybox data-src="#modal" data-zakaz="Название товара 2" href="javascript:;">Заказать</a>
<a data-fancybox data-src="#modal" data-zakaz="Название товара 3" href="javascript:;">Заказать</a>

<div style="display: none;" id="modal">
  <form action="">
    <input type="text" value="" name="zakaz">
  </form>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2018-11-28
@IIvanich

$("a").click(function(){
$('form input[name="zakaz"]').val($(this).attr("data-zakaz"));
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question