JS Printing Functions

1. Document.write

Total body content is called document of the web page this function will print variable or statement or array value in web page
Syntax: document.write(“statements”);
Syntax: document.write(“veriables”);
When printing any statement we can also apply html tags but tags must enclose with in codes
<html>
    <head>
               <script language="javascript">
                      var a=10;                                                                                                      document.writeln("InternalScripting");                                
               </script>
    </head>
    <body>
    </body>
</html>

2. Alert

It will print a statement or a variable with in a popup it has only ok option until user accepted
It will not allow loading web page
Syntax: alert(“statement”);
<html>
    <head>
               <script language="javascript">
               var a=10;
               alert("statements");                      
                </script>
    </head>
    <body>
    </body>
</html>

3. Conform

It is also similar to alert box it will take conformation for the user

Syntax: conform(“statement”);

<html>
    <head>
               <script language="javascript">
               var a=10;
               confirm("Do you want to Submit Form?");
               </script>
    </head>
    <body>
    </body>
</html>

4. Prompt

It is also similar to alert or conform but it will take input from the user (it returns input always in string format)

<html>
    <head>
                <script language="javascript">
                var a=10;
                prompt("Please enter your age");
                </script>
    </head>
    <body>
    </body>
</html>

No comments:

Post a Comment