0% found this document useful (0 votes)
2 views3 pages

Sum of Digits JavaScript Function

The document contains an HTML code that implements a simple web form for calculating the sum of the digits of a given number. It includes a JavaScript function that processes the input number and displays the result in a disabled text field. The form is styled with CSS for better presentation.

Uploaded by

vrushabshah10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Sum of Digits JavaScript Function

The document contains an HTML code that implements a simple web form for calculating the sum of the digits of a given number. It includes a JavaScript function that processes the input number and displays the result in a disabled text field. The form is styled with CSS for better presentation.

Uploaded by

vrushabshah10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assigment 8

Code:-
<html>

<head>

<title> Sum of digit </title>

<script>

function sum()

var no,r,sum;

no=[Link]("text1").value;

sum=0;

while(no>0)

r=no%10;

sum=sum+r;

no=parseInt(no/10);

[Link]("text2").value=("Sum of digit is "+sum);

</script>

<style>

form{

border:2px solid black;

width:200px;

height:fit-content;
Assigment 8
padding:20px;

margin:auto;

margin-top:150px;

</style>

</head>

<body style="text-align:center;">

<h2>Sum of digit</h2>

<form>

<input type="text" placeholder="Enter any no" id="text1">

<br>

<br>

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

<br>

<br>

<input type="button" value="Enter" onclick="sum()">

</form>

</body>

</html>
Assigment 8

Output:-

You might also like