Simple increment program in Javascript with source code(using HTML, CSS, JAVASCRIPT)

 Hey folks, here is a simple javascript program to increment the value by one by clicking on a button, as a new programmer we face lots of delima like what to learn, where to learn what type of framework should i master and many more, so we should start from basic of the programming world like creating a incremental program which return +1 value when you hit the button.

 


So here is html code:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

</head>

<link rel="stylesheet" herf="count.css">

<script src="countjs.js"></script>

<body>

    <div class="heading">D CODER</div>

    <div class="count">

        <button id="dadd" onclick="inc()">+</button>

        <input type="text" id="text">

    </div>

</body>

</html>

In this HTML code i created one div for my page heading then add a button and input tag in div count.

Whereas onclick(when hit a click) tag has function inc(), which is later call in javascript.

JAVASCRIPT CODE

var a=1;

function inc(){

var disp = document.getElementById('text');

disp.value = a;

a++;

}

In this javascript let a value a equal to 1 then call the function inc() which is created in html, after that display value of a in textfield by method document.getElementbyId('text'); and at last increment the value by using a++;

Here i also use basic CSS to make this program bit presentable.

So that's
all for today, i'll post some more program regarding javascript.

If you have any doubt regarding this program please comment down below.

Happy Coding 

Comments

Popular posts from this blog

Margin in CSS-Explained

Language knowledge for Front end developement(Complete road-map)