Cannot read property ‘preventDefault’ of undefined in javascript error

In Console I got following error using e.preventDefault() method I used e as a function parameter

  function function1(e){
     e.preventDefault();
   } 

1533 Uncaught TypeError: Cannot read property ‘preventDefault’ of undefined.

Called function1 like

    <a href="#none" onclick="function1()">Click Me</a> 

Answer

I remove event from function and invoke function in this way:

<button class="btn btn-primary" runat="server" id="btnSave" type="submit"                                           
          onserverclick="btnSave_OnServerClick"  onclick="return 
          jsFunction();">Save</button>

In JavaScript:

function jsFunction() {
        alert('call');
        if ($('#form1').bootstrapValidator('validate').has('.has-error').length) {
            alert('SOMETHING WRONG');             
        } else {
            alert('EVERYTHING IS GOOD');
            __doPostBack('<%=btnSave.UniqueID%>', '');
          }
        return false;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *