Need some help regarding JavaScript
Hi guys I need your help, is it possible to insert <script> tag inside the body section of an HTML page
<html>
<body>
<script type="text/javascript">
alert("how are you");
</script>
</body>
</html>
Hi guys I need your help, is it possible to insert <script> tag inside the body section of an HTML page
<html>
<body>
<script type="text/javascript">
alert("how are you");
</script>
</body>
</html>
Hey Laura!
HTML language is not much difficult. This language is your first step towards programming language.
There are many free sites on internet that can teach you HTML very easily and thoroughly.
Well the answer or your question is “YES”. It is possible that you can use the SCRIPT tag within the body section of HTML.
I will recommend you a free website to learn about programming languages specially HTML. This site helped me a lot when I was learning HTML language. I am sure you will find this site beneficial.
Here is a link for you:
Thanks
Tunacao Caaron
Hi Laura,
The answer is yes.
There are several ways of dealing with JavaScript for your case is Ok positioning in the body.
Another case is inserting in the head such that you call the function within the main body after an event has been trickered.
For example
<HTML>
<HEAD><SCRIPT>
Function sumDigits(num) {
var i, sum = 0; // can declare two variables at once
for (i = 1; i <= num; i++) {
sum += i; // add each number to sum (ie, 1 + 2 + …+ num)
}
// Display result
alert("The sum of the digits from 1 to "+ num + " is:nnt " + sum);
}
</SCRIPT></HEAD>
<BODY>
Looping Functions – Calculate the sum of the digits.
<FORM NAME="SumNums">
The sum of the digits from 1 to:
<INPUT TYPE="text" NAME="charNum">
<INPUT TYPE="button" VALUE="Calculate"
onClick="sumDigits(SumNums.charNum.value)">
</FORM>
</BODY></HTML>
Thanks
Please let me know was this information helpful.
Thank you.