V
V
Vladimir Shiklgruber2015-07-04 15:11:34
htaccess
Vladimir Shiklgruber, 2015-07-04 15:11:34

Why is sambit click not handled?

Hello. Here is a function. By clicking on the link, it uses the htm5 isporia api (this part works), and if it is on the button, it should call this function https://gist.github.com/bullgare/5336154 (the sambit check part does not work)

window.onload = function () {
    var FullList = document.getElementById('contentHolder');
    FullList.addEventListener('click', Content, false);  
    function Content(e) {
        var link = e.target;
        //если нажали на ссылку
        if (link.nodeName.toLowerCase() === 'a') {
            getContent(link, true);
            e.preventDefault();
        }
        //если нажали на самбит
        if (link.nodeName.toLowerCase() === 'submit') {
            alert(serialize(document.forms[0]));
        }
 
    }
    ;
};

How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petrov, 2015-07-04
@aaadddminnn

Because nodeName is the name of the node, and submit is not a tag, but an attribute value.
And you need to check not click on the button, about submitting the form.

document.addEventListener('DOMContentLoaded', function () {
  var FullList = document.getElementById('contentHolder');

  FullList.addEventListener('click', function (e) {
    if (e.target.nodeName == 'A') {
      e.preventDefault();
      getContent(e.target, true);
    }
  });
  FullList.addEventListener('submit', function (e) {
    if (e.target.name == 'Имя_Формы') { // При наличии нескольких форм внутри FullList
      e.preventDefault();
      console.log(serialize(e.target));
    }
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question