Hey. There is a link and an event has already been hung up on it that adds the item to the basket, it is necessary that in addition to adding to the basket a call to a modal window is performed, I call this: class="md-trigger" data-modal="modal-16" .

How to add a link to the second event call?

Reference code below:

 <a href="#" onclick="submitaction('{{url('catalog/order/add')}}')"> <p> ADD TO CART </p> </a> 

Closed due to the fact that the essence of the question is not clear to the participants of the Grundy , D-side , Vartlok , user194374, Peter Olson Apr 7 '16 at 2:19 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • so add this class and attribute to the link - Grundy
  • I do this, but the modal window does not work, the removal of the modal window is working. <a href="# " class="md-trigger " data-modal= " modal-16" onclick= " submitaction('{ [yaurll'catalog/order/add ' ) ′ ') '
  • one
    :-D what does calling a modal window mean? :) It's just a class and attribute. - Grundy
  • one
    To add multiple event handlers, use addEventListener . - Roman Grinyov
  • one
    @ w3lifer, there used to be a comment that some kind of library is used for modal windows, it is by default and should add handlers by itself - Grundy

2 answers 2

Well, if we talk about the right decision, it is better to create a separate method in which you will call the "submitaction" method with the necessary parameters, and then call the method of opening the modal window. Example:

 function myFunc (url) { submitaction('{{url('+url+')}}'); // дальше метод вызова модального окна вида // $('#someModal').modal({...props}); - пример для jquery } 

And already the function "myFunc" put on the event onClick="myFunc(url /*...props*/)"

    Use the addEventListener method, you can hang up the link, as different events with different functions, and many functions for one event.

    If you use the click event on the link, do not forget in the handler to cancel its action on the default click event, by the preventDefault() method.

     var magicLink=document.getElementById("magiclink"); magicLink.addEventListener("click",function(e){e.preventDefault();alert("Я сработал первым!");},false); magicLink.addEventListener("click",function(e){e.preventDefault();alert("А я вторым!");},false); magicLink.addEventListener("mouseout",function(){alert("Вернись!")},false); 
     <a href="#" id="magiclink">Text</a>