Write a JavaScript program to count and display the items of a dropdown list, in an alert window

 <!-- //Write a JavaScript program to count and display the items of a dropdown list, in an alert window -->

<!DOCTYPE html>
<html>

<head>
    <meta charset=utf-8 />
    <style type="text/css">
        body {
            margin30px;
        }

        #confirm {
            displaynone;
            background-color#F3F5F6;
            color#000000;
            border1px solid #aaa;
            positionfixed;
            width300px;
            height100px;
            left40%;
            top40%;
            box-sizingborder-box;
            text-aligncenter;
        }

        #confirm button {
            background-color#FFFFFF;
            displayinline-block;
            border-radius12px;
            border4px solid #aaa;
            padding5px;
            text-aligncenter;
            width60px;
            cursorpointer;
        }

        #confirm .message {
            text-alignleft;
        }
    </style>
    <title>Count and display items of a dropdown list - w3resource</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

<body>
    <div id="confirm">
        <div class="message" id="idmsg">This is a warning message.</div><br>
        <button class="yes">OK</button>
    </div>
    <input type="button" value="Click Me" onclick="functionAlert();" />
    <form>
        Select your favorite Color :
        <select id="mySelect">
            <option>Red</option>
            <option>Green</option>
            <option>Blue</option>
            <option>White</option>
        </select>
        <input type="button" onclick="getOptions()" value="Count and Output all items">
    </form>

    <script>
        function functionAlert(msgmyYes) {
            var confirmBox = $("#confirm");
            confirmBox.find(".message").text(msg);
            confirmBox.find(".yes").unbind().click(function () {
                confirmBox.hide();
            });
            confirmBox.find(".yes").click(myYes);
            let idmsg =document.getElementById('idmsg').style.textAlign = "center";
            confirmBox.show();
        }
        function getOptions() {
            let mySelect = document.getElementById('mySelect');
            let length = document.getElementsByName('option').length;
            alert(mySelect.length);
            functionAlert(mySelect.length);
        }
    </script>
</body>

</html>

Comments

Popular posts from this blog

Write a JavaScript program to get the current date.

Store and display the values of text boxes of a form