0

I have the following HTML Form displayed, and I would like to call the javascript function sendMail() when the user clicks on the Send button:

<script type="text/template" id="compose-view-template">
<form id="email-compose" class="form-email-compose" method="get" action="javascript:sendMail();">
    <div class="form-group">
        <input type="email" id="input-to" placeholder="To" class="input-transparent form-control"
               value="<%= receiver %>">
    </div>
    <div class="form-group">
        <input type="text" id="input-subject" placeholder="Subject" class="input-transparent form-control"
               value="<%= subject %>">
    </div>
    <div class="form-group">
        <textarea rows="10" class="form-control" id="wysiwyg" placeholder="Message"><%- body %></textarea>
    </div>
    <div class="clearfix">
        <div class="btn-toolbar pull-xs-right">
            <button type="reset" id="compose-discard-button" class="btn btn-gray">Cancel</button>
            <button type="submit" id="compose-send-button" onclick="" class="btn btn-danger">&nbsp;&nbsp;&nbsp;Send&nbsp;&nbsp;&nbsp;</button>
        </div>
    </div>
</form>

and the Javascript function:

function sendMail(){

console.log("submit new email");

}
</script> 

but when I click on Send, I have the following error

Form submission canceled because the form is not connected

even if I mention an action to the form or to the button onclick I still have the same error. anybody knows how I can solve this issue ?

tiamat
  • 879
  • 2
  • 12
  • 35
  • what does `method="get" action="javascript:sendMail();"` suppose to do? – Sal-laS Nov 10 '17 at 06:46
  • to be honest I tried multiple ways to launch my Javascript function sendMail while clicking on Send Submit button, but either onSubmit or action doen't work, I still have the same error – tiamat Nov 11 '17 at 08:32

1 Answers1

1

Here is a sample of html page, which there is a button on it, and when u click on it, a javascrippt function shows up, and write a message on your page for you.

Notice:

To send a real email, you must make a backEnd code for it.

                <script>
                    function sendRequest(){
                       console.log( "complete the function");
                       document.getElementById("data").innerHTML = "Email is sent!";
    
                    }
    
                  </script>  
    <!DOCTYPE html>
    <html>
    <body>
    
        <button type="button" onClick="sendRequest()" >Click me </button>
    
        <p id="data"> <p>

    </body>
    </html
Sal-laS
  • 11,016
  • 25
  • 99
  • 169
  • yes it helps me but I still have the message Form submission canceled because the form is not connected... – tiamat Nov 11 '17 at 19:34
  • yes, my js function is called but still get the error – tiamat Nov 11 '17 at 21:59
  • could u please update ur question, so i would now ur current state. also please remove all ur comments from here, and i can ask more from u. – Sal-laS Nov 12 '17 at 04:19
  • Also, please try these solutions: https://stackoverflow.com/questions/42053775/getting-error-form-submission-canceled-because-the-form-is-not-connected – Sal-laS Nov 12 '17 at 04:36