Skip to main content

Basic form

Basic form

<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSFORM</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

    <style>
        span{
            color: red;
        }
    </style>

</head>

<body>
    <form name="basicform" onsubmit="return fun()" >
        <div class="row">
            <label for="colFormLabelLg" class="col-sm-2 col-form-label col-form-label-lg"> Name </label>
            <div class="col-sm-10">
                <input type="text" name="name" placeholder="Name" />
                <span id="nameerror"></span>
            </div>
            <div class="row">
                <label for="col-form-label-lg" class="col-sm-2 col-form-label col-form-label-lg"> Mobile </label>
                <div class="col-sm-10">
                    <input type="text" name="mobile" placeholder="Mobile Numbers" />
                    <span id="mobileerror"></span>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-10">
                <input type="submit" value="Register" class="btn btn-primary">
               
            </div>
        </div>
    </form>

<!-- SCRIPT -->

    <script>
        function fun() {
            var name,mobile,result,error=0;
            name= document.forms.basicform.name.value;
            mobile= document.forms.basicform.mobile.value;
            /////validate first number
            if (name==="")
            {
                //alert("first No. is Mandatory");
                document.getElementById("nameerror").innerHTML="name is Mandatory";
                error=1;

            }
            else if(!isNaN(name ))
            {
                // alert("only Numerical value allowed");
                document.getElementById("nameerror").innerHTML=" Numbers not Allowed";
                error=1;
            }
            ////////// Validate second number
           
            if(mobile==="")
            {
                //alert("mobile is Mandatory");
                document.getElementById("mobileerror").innerHTML=" mobile is Mandatory";
                error=1;
            }
            else if(isNaN(mobile ))
            {
                document.getElementById("mobileerror").innerHTML=" Enter numerical value";
                error=1;
            }


            if (error===1)
            {
                return  false;
            }
           
            else{
                result=parseInt(name)+ parseInt(mobile);
                alert("Result="+result);
            }
        }
    </script>

</body>

</html>

Comments

Popular posts from this blog

Memory Unit Computer Architecture

  Memory Hierarchy A memory unit is an essential component in any digital computer since it is needed for storing programs and data. Typically, a memory unit can be classified into two categories: The memory unit that establishes direct communication with the CPU is called  Main Memory . The main memory is often referred to as RAM (Random Access Memory). The memory units that provide backup storage are called  Auxiliary Memory . For instance, magnetic disks and magnetic tapes are the most commonly used auxiliary memories. Apart from the basic classifications of a memory unit, the memory hierarchy consists all of the storage devices available in a computer system ranging from the slow but high-capacity auxiliary memory to relatively faster main memory. The following image illustrates the components in a typical memory hierarchy. Auxiliary Memory Auxiliary memory is known as the lowest-cost, highest-capacity and slowest-access storage in a computer system. Auxiliary memory ...

Health Experts Reveal: The Benefits and Serving Sizes of Pomegranate

  Benefits Pomegranate contains a range of antioxidant substances that may help to prevent the development of several chronic diseases such as cancer,  arthritis , and other inflammatory conditions. Pomegranate may also help to protect the memory, and delay the progression of  Alzheimer's disease . अनार में एंटीऑक्सीडेंट पदार्थों की एक श्रृंखला होती है जो कैंसर, गठिया और अन्य सूजन संबंधी स्थितियों जैसी कई पुरानी बीमारियों के विकास को रोकने में मदद कर सकती है। अनार याददाश्त को सुरक्षित रखने और अल्जाइमर रोग के बढ़ने में देरी करने में भी मदद कर सकता है। Pomegranate boosts immunity. Pomegranates are rich in vitamin C, potassium and antioxidants called polyphenols that contribute to the protection and proper functioning of cells. In addition, they fight free radicals that weaken the immune system. Pomegranate is effective in reducing the risk of chronic disease. Pomegranate has impressive anti-inflammatory properties which are mediated by bioactive compounds present in pomegra...