There are a number of inbuilt JavaScript functions for this. alert() and document.write() are two of the most widely used JS functions for outputting JS texts from a webpage
alert( );
The alert function displays a dialogue box with the parameters of the function as content.
alert("How are you"); //This displays "How are you" in a dialogue box on the screen. Ok, let us write a proper JS code in its proper HTML tag.
<html>
<head>
<script type="text/javascript" language="javascript">
alert("How are you");
</script>
</head>
<body>
</body>
</html>
The code above displays the image below;
Now, this is a dialogue box with an attitude. It basically freezes the webpage until you click on the OK button. All data-types can be put on a dialogue box basically.
var number1 = 34;
var number2 = 22;
alert(2); <- This prints a numeric value 2 on a dialogue box and displays it.
alert(number1 + number2); <- This prints 56 on a dialogue box and displays it,
document.write( );
This function takes a lighter approach to displaying user input. Unlike alert( ), it does not print it's parameter on a dialogue box. Rather, it displays it directly on a webpage.
<html>
<head>
<script type="text/javascript" language="javascript">
document.write("How are you");
</script>
</head>
<body>
</body>
</html>
The code above displays the image below;
There are more methods basically that writes either to a webpage or to form elements such as textboxes. Methods such as .innerHTML and .value (Note the dot in before the words). These methods will be discussed in future blogposts.
Hope this helps someone out there.
Feel free to drop comments, suggestions and criticisms in the comment section below.
Joseph Kayode Agbede
alert( );
The alert function displays a dialogue box with the parameters of the function as content.
alert("How are you"); //This displays "How are you" in a dialogue box on the screen. Ok, let us write a proper JS code in its proper HTML tag.
<html>
<head>
<script type="text/javascript" language="javascript">
alert("How are you");
</script>
</head>
<body>
</body>
</html>
The code above displays the image below;
var number1 = 34;
var number2 = 22;
alert(2); <- This prints a numeric value 2 on a dialogue box and displays it.
alert(number1 + number2); <- This prints 56 on a dialogue box and displays it,
document.write( );
This function takes a lighter approach to displaying user input. Unlike alert( ), it does not print it's parameter on a dialogue box. Rather, it displays it directly on a webpage.
<html>
<head>
<script type="text/javascript" language="javascript">
document.write("How are you");
</script>
</head>
<body>
</body>
</html>
The code above displays the image below;
There are more methods basically that writes either to a webpage or to form elements such as textboxes. Methods such as .innerHTML and .value (Note the dot in before the words). These methods will be discussed in future blogposts.
Hope this helps someone out there.
Feel free to drop comments, suggestions and criticisms in the comment section below.
Joseph Kayode Agbede