简体   繁体   中英

myFunction is not defined in my HTML form

I'm making a form where my send button needs to execute myFunction. But whenever i'm trying to send it to execute i get an Uncaught ReferenceError: myFunction is not defined.

Here is the useful part of the code:

<button type="submit" onclick="myFunction()">VERSTUUR</button>
 </div>

  </fieldset>
<div id="uitvoeren"></div>

<script type="text/javascript">
"use strict";
var vak;
    function myFunction() {
        var naam = document.getElementById("naam").value;
        var Leeftijd = document.getElementById("Leeftijd").value;
        vak=document.getElementsByName("vak");

You are missig some code, i hope that can helps.

    <form action="" method="post">
        <input type="text" name="name" id="name">
        <input type="email" name="email" id="email">
        <input type="password" name="password" id="password">
        <button type="submit" id="btn">VERSTUUR</button>
    </form>


<script type="text/javascript">
"use strict";
    document.getElementById('btn').onclick = myFunction;
    function myFunction(e) {
        e.preventDefault();
        var name = document.getElementById('name').value;
        var email = document.getElementById('email').value;
        var password = document.getElementById('password').value;
        console.table({'name': name, 'email': email, 'password': password})
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM