padfoot
padfoot

Reputation: 21

How to print some javascript code on html page

<html><body>
<p id="demo"></p>

<script>

function validato()
{



 document.getElementById("demo").innerHTML = emailio;

}

function emalio(x,y){

function ValidateEmail(mail) 
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
  {
    return (true)
  }
    alert("You have entered an invalid email address!")
    return (false)
}
 

}

</script>

</body></html>

I tried to print function imalio() as it is on html page by not giving parameter. but it is not doing anything. Please somebody explain it to me.

Upvotes: 0

Views: 72

Answers (1)

martin jakubik
martin jakubik

Reputation: 4148

Quentin is right. You have not called your function.

Add validato() to call your function and it will print the contents of the other function in your HTML element.

<html>

<body>

  <p id="demo"></p>

  <script>
    function validato() {
      document.getElementById("demo").innerHTML = foo;
    }

    function foo(x, y) {
      function bar(z) {
        return (false);
      }
    }

    validato();
  </script>

</body>

</html>

Upvotes: 2

Related Questions