Trigger onclick event in a button element

I have the following button element in a form

<form action="#" method="post" id="commentform" >
<button name="submit"  type="submit" id="submit" onmouseover="email();" >Submit Comment</button>
</form>

Then i have the following javascript code for email function

<script>
   function email(){
   $('document').ready(function (){
      var name=$('#author').val();
      var userEmail=$('#email').val();
      var phone=$('#url').val();
      var subject=$('#subject').val();
      var comment=$('#comment').val();
      var submit=$('#submit').val();
      var form={
          "name":name,
          "userEmail":userEmail,
          "phone":phone,
          "subject":subject,
          "comment":comment,
          "submit":submit          
      };
    console.log(form);
    var array="Ta kena pedia einai: ";
    for (var item in form) {
        array=array+"\n"+"\n"+item+"\n";
        if(item==null){
         return item;
        }
      
    }    
    alert(array); 
   });
   };
 </script>

When i click the submit button the function not working and i have the following error in the console
Uncaught TypeError: email is not a function
at HTMLButtonElement.onmouseover

What is the problem and how i can fix it?

Do you have jQuery loaded?

Thanks Dormilich about the answer.I find a solution and this was so simple.The only that i change is the name of the function from email() to another().

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.