Friday, September 6, 2024

Browser Object Model in javascript

Timing code-

<input type="button" value="Click" onclick="setTimeout(hello, 5000)">

<script>
    function hello(){

       // alert("yes you can go anywhere!!");

       window.location='https://www.google.com/';
    }
</script>    



 Confirm popup code-


<input type="button" value="Click to Know" onclick="hello()">
<p id="show"></p>


<script>
    function hello(){

        var result;
            if(confirm("Yes tell me what you want to do?"))
                {
                        result = "You press OK!!!";
                }
            else{
                        result = "You press Cancel!!!!!!!!";

                }

    document.getElementById("show").innerHTML=result;

}

</script>

Thursday, September 5, 2024

Factorial of any number

 <script>


    var num = 12;
    var z = 1;
    var i;

    for(i=1;i<=num;i++){

     z = z*i;    

    }

    document.write(z);

</script>




Add to Cart (Advanced Tutorial)

 index.html file:


<html>
    <head>
        <title>Advanced Js Cart</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
    </head>
</html>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-7">
            <div class="row" style="background: cornsilk;padding: 20px;text-align: center;">
            <div class="col-md-6">
                <img src="phone.png" id ="pic" width="100"><br>
                Name: Pink Flower<input type="hidden" id = "name" value="Pink Flower"><br>
                Price: Rs 2000<input type="hidden" id = "price" value="2000"><br>
                Description: Good<input type="hidden" id = "description"  value="Good "><br><br>
                <input type="button" onclick="add(1)" class="btn btn-info btn-sm" value="Add to cart">
            </div>
            <div class="col-md-6">
                <img src="other.png" id ="pic2" width="100"><br>
                Name: Red Flower<input type="hidden" id = "name2" value="red Flower"><br>
                Price: Rs 3000<input type="hidden" id = "price2" value="3000"><br>
                Description: Best<input type="hidden" id = "description2" value="Best"><br><br>
                <input type="button" onclick="add(2)" class="btn btn-info btn-sm" value="Add to cart">
            </div>
            </div>
        </div>
        <div class="col-md-1"></div>

        <div class="col-md-4" style="background: #4985c794;">
            Total Cart Item : <b id = "c">0</b>
            <div id="cartval"></div><br>
            <div style="    background: aliceblue;padding: 6px;">Amount<b style="float: right;" id="t">0</b></div>          
           
        </div>
    </div>
</div>
<script src="script.js"></script>
</body>
</html>

script.js file:

var count = 0;
var r = 0;

function add(val){
if(val=='1'){

    var name = document.getElementById("name").value;
    var price = parseInt(document.getElementById("price").value);
    var description = document.getElementById("description").value;
    var img = document.getElementById("pic").src;

    count = count+1;
    document.getElementById("c").innerHTML=count;  

    document.getElementById("t").innerHTML = r;

    document.getElementById("cartval").innerHTML+="<div style='background:white; width:350px;height:100px;'><img style='width:50px;' src="+img+"><br>Name:"+name+" Description:"+description+"<br>Price: "+price+"</div>";
   



}

if(val=='2'){

    var name = document.getElementById("name2").value;
    var price = parseInt(document.getElementById("price2").value);
    var description = document.getElementById("description2").value;
    var img = document.getElementById("pic2").src;
    count = count+1;
    document.getElementById("c").innerHTML=count;

    document.getElementById("t").innerHTML = r;
    document.getElementById("cartval").innerHTML+="<div style='background:white; width:350px;height:100px;'><img style='width:50px;' src="+img+"><br>Name:"+name+" Description:"+description+"<br>Price: "+price+"</div>";
   


}

 r = r+price;
 document.getElementById("t").innerHTML=r;

}






Start your smart training now!

  Call us on - +91-7080234447 or Visit - https://www.websitedevelopmentservices.in/training