Adding Two numbers
This post focuses on adding two numbers, adding two numbers does not mean static value but dynamic inputs with a simple number validation. Below is the step by step procedure.
Create a index.html and place the below code in the body section of the HTML file.
<!DOCTYPE HTML>
<head>
<title>Add two numbers</title>
<script type="text/javascript" src="script.js" >
</head>
<body>
Enter the first number: <input type="text" id="txt1" /><br />
Enter the seccond number: <input type="text" id="txt2" /><br />
<input type="button" onclick="call()" value="Add"/>
</body>
</html>
Create a javascript file(script.js) with the below content.
function call(){
var q=parseInt(document.getElementById("txt1").value);
var w=parseInt(document.getElementById("txt2").value);
var result=q+w;
if(isNaN(q)||isNaN(w)){
alert("please enter a number");
}
else
{
var result=q+w;
alert("The sum is " +result);
}
}
Please do not forget to include the javascript file(script.js) in the index.html.
In this example you would have observed the following javascript terms.
- onclick
- document.getElementById
- parseInt
- isNaN
1. onclick-In the above example onclick it calls the function call();
2. document.getElementById -gets the values entered in the input fields which defined with id's txt1 and txt2.
3.parseInt - converts the value to Int type.
4.isNaN - checks if the value is NaN.
Couple of things to be noted
- document.getElementById always returns a string value, so we need to convert the value to Int(parseInt) for mathematical operations.
- In order to ensure that the entered inputs are only numbers , a if condition is implemented to check the values. If the entered value is not a number then it would alert with(please enter a number).
Thorough this example we can add dynamic inputs and validate.
Hope this post was informative, would be adding some more post shortly.
Thanks... Really helpful
ReplyDeleteI appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.
ReplyDeleterpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
ReplyDeleteAWS Training in pune
AWS Online Training
AWS Training in Bangalore
Attend The Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Bangalore.
ReplyDeleteReally very informative post you shared here.It's a great skill to make even the person who doesn't know about the subject could able to understand the subject .Keep it up!! Machine Learning Training in Bangalore
ReplyDeleteood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge, keep blogging!! Machine Learning Course
ReplyDeleteVisit for AWS training in Bangalore:- AWS training in Bangalore
ReplyDeletegood post thank you for sharing...........Artificial intelligence course hyderabad
ReplyDeleteThanks. Nice blog!! Very useful information is providing by your blog.
ReplyDeleteAWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
I gathered lots of information from your blog and it helped me a lot. Keep posting more.
ReplyDeleteAngular JS Training in Chennai | Certification | Online Training Course | Angular JS Training in Bangalore | Certification | Online Training Course | Angular JS Training in Hyderabad | Certification | Online Training Course | Angular JS Training in Coimbatore | Certification | Online Training Course | Angular JS Training | Certification | Angular JS Online Training Course
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging.After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeletehttps://www.3ritechnologies.com/course/mern-stack-training-in-pune/
log.Very informative post.Check this python classroom training in bangalore
ReplyDeleteNice post. Check this Ethical Hacking Training In Bangalore
ReplyDeleteWow such an amazing content keep it up. I have bookmarked your page to check out more informative content here.
ReplyDeleteSASVBA Delhi provides extensive MERN STACK COURSE IN DELHI The extensive hands-on session, hosted by the MERN Stack Training Institute in Delhi, includes live projects and simulations.
FOR MORE INFO:
David Forbes is president of Alliance Marketing Associates IncIamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder
ReplyDeleteAnnabelle loves to write and has been doing so for many years.iamlinkfeeder1 iamlinkfeeder1 iamlinkfeeder1
ReplyDeleteImpressive. Your story always bring hope and new energy. Keep up the good work.
ReplyDeleteBest Data Science courses in Hyderabad
This post is so interactive and informative.keep update more information…
ReplyDeleteAndroid Training in Anna Nagar
Android Training in Chennai
This post is so interactive and informative.keep update more information...
ReplyDeleteData Science course in Tambaram
Data Science course in Chennai
شركات عزل الاسطح بجدة
ReplyDeleteI am really happy to say it’s an interesting post to read. I learn new information from your article, you are doing a great job. Keep it up
ReplyDeleteSoftware Testing Tools Training in Hyderabad
wordpress web design company in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!
ReplyDeleteGood content. You write beautiful things.
ReplyDeletesportsbet
korsan taksi
mrbahis
taksi
hacklink
vbet
sportsbet
vbet
hacklink
Success Write content success. Thanks.
ReplyDeletebetpark
kralbet
canlı poker siteleri
betturkey
betmatik
deneme bonusu
kıbrıs bahis siteleri
Nice article...Thanks for sharing...
ReplyDeleteartificial intelligence training in Pune
slot siteleri
ReplyDeletekralbet
betpark
tipobet
betmatik
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
CHOX6M
betmatik
ReplyDeletekralbet
betpark
mobil ödeme bahis
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
24WDNL
Thanks for sharing such a wonderful post with us.
ReplyDeleteFrontend development course in Pune
kocaeli
ReplyDeletekonya
kuşadası
kütahya
malatya
DKPJ
başakşehir
ReplyDeletebeykoz
gölcük
kütahya
bandırma
P88K
kars
ReplyDeletekütahya
niğde
urfa
aydın
FEZH
Great post.very informative.
ReplyDeleteJava Course in Nagpur
Unified communications and Ip Pbx includes the connection of various communication systems both for the collaboration tools as the digital workforce.
ReplyDeleteدهانات ديكورية
ReplyDeleteمواد انشائية
Thanks for the post.
ReplyDeletealso, check Java course in Pune
شركة تنظيف بالجبيل Kyc3meq5mF
ReplyDeleteشركة تنظيف شقق بالدمام CCFXWpDgNh
ReplyDeleteشركة مكافحة حشرات بالدمام wjAmcUY8FB
ReplyDelete