Home
• Programming • JavaScript
May 2nd, 2013 at 10:56 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <script> function myFunction(){ var total=0; var i=1; while(i<10){ total=total+i; i=i+1; } document.getElementById("asha").innerHTML=total; } </script> <input type="button" value="Click" onclick="myFunction()" /> <p id="asha">Show here</p> </body> </html>
First
Prev
Next
Last
/50
Tweet
Comments 5
see now
Put document.getElementById("asha").innerHTML=total; inside the funciton
And you missed function parenthesis at onclick event when you call function
var total is local variable not global. outside funtion total variable will not be detected.
Ok I understand. Thanks
Comment
Share
About Author
Mohammad Towhidul Islam
University
Campus
334+
Online Tips
Study
29+
Computer
107+
Religious
30+
Fashion & Design
9+
Agriculture
55+
VCampus Help
25+
Intorior Design
18+
Photography
15+
Health
64+
Mobile
2+
SEO
8+
ASCII Art
7+
Phone Book
2+
Shopping
1+
Music
7+
Recipe
1+
Engineering
Computer
12+
EEE
1+
Programming
Java
33+
C#.NET
23+
C++
4+
JQuery
10+
PHP
46+
HTML5
14+
C
15+
CSS
32+
ASP.NET
14+
JavaScript
50+
Microsoft .NET Framework
10+
JSP
1+
SQL
3+
PLSQL
1+
XML
4+
Angular
7+
Bash shell
1+
Python
2+
Perl
1+
XSL
2+
ReactJS
11+
General Subjects
Drawing
10+
Computing
7+
English
20+
Math
6+
Politics
3+
Social & Culture
1+
Biography
1+
Science
Physics
3+
Chemistry
5+
Biology
3+
News
Sports News
3+
Weather News
7+
Entertainment News
2+
Career News
3+
International News
1+
Jobs
Education/Training
1+
IT & Telecommunication
9+
Others
2+
Commerce
Accounting
23+
Management
4+
Economics
1+
General Knowledge
Bangladesh
8+
Science & Technology
11+
English & Literature
4+
International
5+
Others
5+
Bengali & Literature
3+
Current affairs
1+
Mathematics
2+
Story, Tales & Poem
Fiction
1+
Jokes
6+
Poem
1+
Software Application
Microsoft Excel
3+
Adobe Photoshop
2+
Adobe Flash
1+
Editors
1+
Microsoft Word
1+
Framework
Wordpress
15+
phpBB
1+
Laravel
12+
CodeIgniter
4+
Bootstrap
2+
Yii
7+
CakePHP
17+
Magento
10+
Operating System
DOS
2+
Linux
2+
Database
MySQL
25+
Oracle
3+
IBM DB2
1+
Microsoft SQL Server
13+
Microsoft Access
1+
Networking
Computer Networks
3+
Networking Services
1+
Data Communication & Networking
1+
Quiz
Other
1+
Schools
Whiteboard
Quiz
Test
Apply Course
Games
Freelancers
Professionals
Newspapers
Terms
Privacy
Copyright © 2024. Powered by
Intellect Software Ltd
Comments 5