HTML

MULLY BENDET
MULLY BENDET
509 Points

why did it not work

<button onclick="myFunction1();" id="myd">save</button>

<script> function myFunction1(){ var email = prompt("whats your email");

} document.getElementById("myd").href = "mailto:" + email + "?subject=Cabbages"; </script>

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 23,930 Points

If you open the javascript console you'll see email is undefined for

document.getElementById("myd").href = "mailto:" + email + "?subject=Cabbages"; </script>

because it outside the function where it is declared (check your closing curly brace).

I'm not sure what you are trying to do from there but one way to send mail would be:

  <button onclick="myFunction1();" id="myd">save</button>
  <script>
    function myFunction1(){
      var email = prompt("whats your email");
      window.open("mailto:" + email + "?subject=Cabbages");
    }
  </script>