0

<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.

5
  • 2
    Your JavaScript defines a couple of functions but never calls them. Why do you expect it to do anything? Commented Jan 9, 2017 at 16:03
  • You also have a function defined within a function, which probably won't do what you think it does. Commented Jan 9, 2017 at 16:06
  • well, I was trying to print complete function itself as an output. so if my upper level function fails in calling with its parameters then it should print the whole containt inside it as it is as a function definition. Commented Jan 9, 2017 at 16:12
  • Basically what I am trying to do here is that I am trying to print different javascript code blocks as output on html page on clicking different buttons. Commented Jan 9, 2017 at 16:16
  • @padfoot, also you named your function "emalio" but when you try to print it you used "emailio". Commented Jan 10, 2017 at 11:12

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.